Skip to content

Practice Count the Hidden Sequences

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2145
LeetCode Problem

Count the Hidden Sequences

Problem Statement

You are given a 0-indexed array of n integers differences, which describes the differences between each pair of consecutive integers of a hidden sequence of length (n + 1). More formally, call the hidden sequence hidden, then we have that differences[i] = hidden[i + 1] - hidden[i]. You are further given two integers lower and upper that describe the inclusive range of values [lower, upper] that the hidden sequence can contain. Return the number of possible hidden sequences there are. If there are no possible sequences, return 0.

Source: Count the Hidden Sequences on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
differences = [1,-3,4], lower = 1, upper = 6
Output
2

# Example 2

Input
differences = [3,-4,5,1,-2], lower = -4, upper = 5
Output
4

# Example 3

Input
differences = [4,-7,2], lower = 3, upper = 6
Output
0

Constraints

n == differences.length
1 <= n <= 10^5
-10^5 <= differences[i] <= 10^5
-10^5 <= lower <= upper <= 10^5

Related LeetCode Problems

Practice more problems similar to Count the Hidden Sequences.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.