Pregunta de entrevista de Globant

I was asked a programming Leetcode-type question in Javascript