Pregunta de entrevista de Microsoft

A medium difficulty algorithm problem