Pregunta de entrevista de Microsoft

Require best algorithm both in time and space