Pergunta de entrevista da empresa Google

Problem to be solved with general data stractures and some logic