Apple Interview Question

Leetcode.