Accenture interview question

A medium array question - usual leetcode stuff