Palo Alto Networks interview question

leetcode medium based array question