2145. Count the Hidden Sequences

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2145

class Solution:
    def numberOfArrays(self, differences: List[int], lower: int, upper: int) -> int:
        num = mi = mx = 0
        for d in differences:
            num += d
            mi = min(mi, num)
            mx = max(mx, num)
        return max(0, upper - lower - (mx - mi) + 1)