Pregunta de entrevista de Google

Complexity of the solution I provided.