IXL Learning interview question

Leetcode medium to hard, just do blind 75