Pregunta de entrevista de Virtasant

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