Pergunta de entrevista da empresa Google

Had one algorithm/coding question to solve per interview.