Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional
How many contiguous subarrays of [3, 1, 3, 2, 3, 1] have their maximum value occurring EXACTLY twice inside the subarray?
- A. 8
- B. 5
- C. 21
- D. 6
Correct answer: D. 6
Brute force over subarrays with a count of the maximum, or a monotone stack giving for each element the span where it is the maximum. Counting subarrays where the 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
- How many strings of length 5 over the alphabet {a, b, c} contain no two adjacent equal letters when the letter is a or b (two adjacent c's…
- How many binary strings of length 6 have exactly 4 maximal runs (blocks of equal consecutive digits)?
- How many unordered pairs of different positions in [3, 8, 2, 9, 5, 4] have a product at most 24?
- What is the smallest period of the string "abaababaab"? The smallest period p is the least p > 0 such that s[i] = s[i + p] for every valid…
- What is the length of the longest proper border of "abacabacabab"? A border is a non-empty proper prefix that is also a suffix.
- Array [2, 3, 1, 4, 2, 5, 1, 2]: from index i you may jump to any index j with i < j ≤ i + a[i]. Landing on index j costs a[j]. Starting at…