Pergunta de entrevista da empresa Target

Solve a puzzle, which I saw in geeksforgeeks