Domanda di colloquio di Globant

I was asked a programming Leetcode-type question in Javascript