Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional
What is the sum over all subarrays of [3, 1, 2, 4] of the minimum element of each subarray?
- A. 17
- B. 30
- C. 18
- D. 40
Correct answer: A. 17
Each element is the minimum of (its left span) times (its right span) subarrays, computed with a monotonic stack. Summing over all subarrays by brute force gives the same 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
- Using a monotonic deque, the window maximum for every window of size 3 over [1, 3, -1, -3, 5, 3, 6, 7] is listed left to right. What is…
- In the array [1, 2, 1, 3, 2, 5] exactly two values appear once and every other value appears twice. Which two values are they, as a sorted…
- What is the value of sum of popcount(i) for i from 1 to 20 (number of 1-bits in the binary form of each i, summed)?
- For the array [6, 12, 5, 8], what is the sum of (x & -x) over all elements x, where x & -x is the lowest set bit of x?
- How many contiguous subarrays of [1, 2, 4, 3, 6] have a bitwise OR equal to exactly 7?
- How many distinct non-empty substrings does the string "abacaba" have?