IXL Learning interview question

Leetcode medium with a bit of OOP