Pregunta de entrevista de Bloomberg

Hackerrank question related to data structures and algorithms