Capital One interview question

Python - Leetcode arrays problem