Pergunta de entrevista da empresa HackerEarth

it's on the leetcode discussion you can find it