Qualcomm interview question

leetcode question from blind 75