Apple interview question

leetcode hard technical interview problem