Tap here to switch tabs
Problem
Submissions

Problem: Count the Hidden Sequences

Try to solve the Count the Hidden Sequences problem.

Statement

You are given an integer array differences of length n, and two integers lower and upper. A hidden integer array hidden of length n + 1 is considered valid if it satisfies both conditions:

The value at each index stays within the inclusive range from lower to upper.

For every index i in the range from 00 to n−1n - 1, the adjacent difference matches differences, meaning hidden[i + 1] - hidden[i] == differences[i].

Return the number of distinct valid arrays hidden that can be formed.

Constraints:

  • n == differences.length

  • 1≤1 \leq n ≤105\leq 10^5

  • −105≤-10^5 \leq differences[i] ≤105\leq 10^5

  • −105≤-10^5 \leq lower ≤\leq upper ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count the Hidden Sequences

Try to solve the Count the Hidden Sequences problem.

Statement

You are given an integer array differences of length n, and two integers lower and upper. A hidden integer array hidden of length n + 1 is considered valid if it satisfies both conditions:

The value at each index stays within the inclusive range from lower to upper.

For every index i in the range from 00 to n−1n - 1, the adjacent difference matches differences, meaning hidden[i + 1] - hidden[i] == differences[i].

Return the number of distinct valid arrays hidden that can be formed.

Constraints:

  • n == differences.length

  • 1≤1 \leq n ≤105\leq 10^5

  • −105≤-10^5 \leq differences[i] ≤105\leq 10^5

  • −105≤-10^5 \leq lower ≤\leq upper ≤105\leq 10^5