Apply Operations To An Array Leetcode Problems Python