Globant interview question

I was asked a programming Leetcode-type question in Javascript