Pregunta de entrevista de VNG Corporation

Leet code problem, Data structure and algorithm question