Apple Interview Question

One of the question from leetcode