Pregunta de entrevista de Google

Technical: the solution, walking through it and expected runtime