Data Structures & AlgorithmsHard
How many contiguous subarrays of 3 3 2 4 1 2 have a sum EXACTLY equal to (their length) × (their minimum)?
- A. 21
- B. 7
- C. 2
- D. 8
Correct answer: B. 7
Equality with length times the minimum says every element equals the minimum, so the qualifying blocks are constant runs. Using the maximum, a non-strict bound, or adding one changes the total.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Why does the OR of a subarray change at most about log(maximum value) times as its right end extends from a fixed start?
- Why is the OR of a subarray always at least the maximum element of that subarray?
- When counting triangles from sorted stick lengths with a two-pointer scan, why does fixing the largest side k and moving the pointers i <…
- Why is the inequality test for a non-degenerate triangle with sorted sides written as ai + aj > ak for the largest side ak?
- To count subarrays with sum divisible by m, why does the equal-residue method fail for a subarray count that depends on the MAXIMUM element?
- In the 'longest window with equal numbers of high and low values' problem, what turns the condition into a standard prefix-sum problem?