OKG interview question

leetcode solving problem. medium level related with array.