Pergunta de entrevista da empresa Microsoft

Require best algorithm both in time and space