Pergunta de entrevista da empresa Virtasant

Solve this problem from leet code: [leet code problem]