Skip to content
LC-1526 Hard LeetCode

1526. Minimum Number of Increments on Subarrays to Form a Target Array

Read the full problem statement on LeetCode.
Difficulty: hard Acceptance: 72% Topics: Array, Dynamic Programming, Stack, Greedy, Monotonic Stack
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def minNumberOperations(self, target):
        """
        :type target: List[int]
        :rtype: int
        """
        return sum(max((target[i] if i < len(target) else 0)-(target[i-1] if i-1 >= 0 else 0), 0) for i in xrange(len(target)+1))

Solution from kamyu104/LeetCode-Solutions · MIT