Apply Operations to an Array | Leetcode 2460