Pregunta de entrevista de Wise

hackerrank type question involving data structures