Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional
How many contiguous subarrays of [3, 1, 3, 2, 5, 2, 5] contain exactly one occurrence of their maximum value?
- A. 24
- B. 21
- C. 19
- D. 28
Correct answer: B. 21
For each subarray, the maximum must appear exactly once. Counting with monotonic stacks on the nearest greater-or-equal elements on each side works in O(n) per element. Counting subarrays whose maximum appears at least once is a different (larger) quantity.
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
- What is the length of the longest contiguous block of [1, 2, 3, 1, 2, 3, 4, 2, 3, 4] that appears at least twice in the array WITHOUT…
- What is the length of the longest subsequence of [1, 2, 4, 5, 7, 8, 10] that is strictly increasing and in which every two consecutive…
- Using swaps of ADJACENT elements only, what is the minimum number of swaps needed to sort the binary array [1, 0, 1, 1, 0, 0, 1, 0] so…
- How many unordered pairs of positions in [3, 4, 7, 10, 2, 9] have an element sum that is a prime number?
- Coins of values 1, 5, 6 and 9 are available in unlimited supply. What is the minimum number of coins needed to make exactly 11?
- In how many ways can 100 paise be paid using coins of 1, 5, 10 and 25 paise, where the order of coins does not matter?