Apple interview question

One of the question from leetcode