Apple Interview Question

Leetcode Hard question