Qualcomm Interview Question

leetcode question from blind 75