Pergunta de entrevista da empresa Google

Started with a simple question and moved on to add complexity in the problem