Data Structures & AlgorithmsHardCodeforces Div2 B · ICPC regional
Rain falls on the elevation map [4, 2, 0, 3, 2, 5] (each bar has width 1). How many units of water are trapped in total?
- A. 8
- B. 9
- C. 10
- D. 18
Correct answer: B. 9
Water above bar i is min(max height to its left, max height to its right) minus its own height. Using only the left maximum overestimates the water.
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 contiguous subarrays of [1, 2, 1, 2, 3, 3, 4] contain at most 2 distinct values?
- How many non-empty contiguous subarrays of [10, 5, 2, 6] have a product strictly less than 100?
- An LRU cache holds 3 keys. Requests arrive in the order 1, 2, 3, 1, 4, 2, 5, 1, 2, 3, 4, 5, and a request for an absent key is a miss that…
- Given the linked list 1 -> 2 -> ... -> 8, the list is reversed in consecutive groups of 3 (a final group with fewer than 3 nodes is left…
- A linked list has a tail of 3 nodes leading into a cycle of 5 nodes. A slow pointer advances 1 node per step and a fast pointer advances 2…
- How many index pairs i < j satisfy (a[i] + a[j]) mod 7 = 0 for the array [3, 4, 7, 10, 11, 14, 21, 5, 9]?