IXL Learning interview question

Leetcode question, not too hard