Data Structures & AlgorithmsHard
How many contiguous subarrays of 1 3 2 5 4 6 1 2 of length at least 3 have exactly one interior strict local maximum (a position strictly inside the subarray that is larger than both its neighbours)?
- A. 18
- B. 10
- C. 11
- D. 9
Correct answer: B. 10
Count interior strict peaks within each block, so the neighbours are those inside the block only. Using at-least-one, non-strict peaks, or zero peaks each change the set.
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
- How many index pairs i < j in 2 5 3 9 4 7 6 satisfy A[i] < A[j] AND (A[j] − A[i]) divides (j − i)?
- How many contiguous subarrays of length exactly 2 in 2 4 7 9 1 3 6 8 consist of two values with the SAME parity?
- How many index triples i < j < k in 1 2 2 3 4 6 8 satisfy A[i] · A[j] = A[k]?
- How many contiguous subarrays of 3 3 2 4 1 2 have a sum EXACTLY equal to (their length) × (their minimum)?
- 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?