Apple interview question

Asked to complete Leetcode style coderpad questions