Count Analogous Arrays
Updated
Problem 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 Online Assessment questions
- 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
- Binary Tree Level Order TraversalOA · Seen Nov 2023
- Design HashMapOA · Seen Nov 2023
Similar questions at other companies
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Count Attack Vectors by Divisor RangeVisa · OAVisa interview questions
- Prefix Scores With the Running MaximumC3.ai · OAC3.ai interview questions
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Array Challenge (QR Intern)Akuna Capital · OAAkuna Capital interview questions
- Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Random Pick with Weight Using Recorded DrawsAmazon · ONSITE INTERVIEW
- Multinomial Sampling with Distribution ChecksNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Random Pick with Weight Using Recorded DrawsMeta · PHONE SCREENMeta interview questions
- Longest Stationary Sensor IntervalWayve · PHONE SCREEN