Pergunta de entrevista da empresa Google

Simple Algo question with Big O Complexity follow-ups