LinkedIn Interview Question

leetcode coding for array and a follow up