Problem · Array
Count Analogous Arrays
Learn this problemProblem statement
A secret integer array is represented by the differences between consecutive values. For an analogous array a, every value must lie in the inclusive interval [lowerBound, upperBound], and for every valid i, a[i] - a[i + 1] = consecutiveDifference[i].
Return the number of analogous arrays. Return 0 when no starting value can keep the entire array inside the interval.
Function
countAnalogousArrays(consecutiveDifference: int[], lowerBound: int, upperBound: int) → intExamples
Example 1
consecutiveDifference = [-2,-1,-2,5]lowerBound = 3upperBound = 10return = 3The valid arrays are [3,5,6,8,3], [4,6,7,9,4], and [5,7,8,10,5].
Constraints
0 <= consecutiveDifference.length <= 100000-10^9 <= consecutiveDifference[i] <= 10^9-10^9 <= lowerBound <= upperBound <= 10^9- The answer fits a signed
int.
More Atlassian problems
- Planning ProductionOA · Seen Feb 2025
- K-Means ClusteringOA · Seen Feb 2025
- Minimum Sorted Erasure OperationsOA · Seen Jun 2024
- Get Maximum ScoreOA · Seen Mar 2024
- Better Compression 🦀OA · Seen Mar 2024
- Romanizer 🐡OA · Seen Mar 2024
- Flower Bouquets 💐OA · Seen Mar 2024
- Binary Search Tree IteratorOA · Seen Nov 2023