LinkedIn interview question

leetcode coding for array and a follow up