diff --git a/medium/count_the_hidden_sequences.py b/medium/count_the_hidden_sequences.py new file mode 100644 index 0000000..3f8fa0e --- /dev/null +++ b/medium/count_the_hidden_sequences.py @@ -0,0 +1,19 @@ +# 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) +