IBM Interview Question

leetcode qn based on array