19 lines
511 B
Python
19 lines
511 B
Python
# https://leetcode.com/problems/count-the-hidden-sequences
|
|
|
|
from typing import List
|
|
|
|
class Solution:
|
|
def numberOfArrays(self, differences: List[int], lower: int, upper: int) -> int:
|
|
total = 0
|
|
min_sum = 0
|
|
max_sum = 0
|
|
for diff in differences:
|
|
total += diff
|
|
min_sum = min(min_sum, total)
|
|
max_sum = max(max_sum, total)
|
|
|
|
min_start = lower - min_sum
|
|
max_start = upper - max_sum
|
|
|
|
return max(0, max_start - min_start + 1)
|
|
|