Pergunta de entrevista da empresa Google

Technical coding question with decent difficulty