Apple interview question

medium leetcode question has been asked