Apple Interview Question

One of the medium leetcode questions