Apple interview question

Typical leetcode easy as well as a behavioral round