Pergunta de entrevista da empresa VNG Corporation

Leet code problem, Data structure and algorithm question