From dd5dcd1f201a0385c0b01e147cacf8f5745ee546 Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Mon, 21 Apr 2025 15:25:58 +0000 Subject: [PATCH] https://leetcode.com/problems/count-the-hidden-sequences --- medium/count_the_hidden_sequences.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 medium/count_the_hidden_sequences.py 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) +