Pergunta de entrevista da empresa Indigo

There was a live coding exercise for a relatively simple problem