Pergunta de entrevista da empresa Google

Complexity of the solution I provided.