Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
What is the area of the largest rectangle that fits in the histogram with bar heights [2, 1, 5, 6, 2, 3]?
- A. 12
- B. 6
- C. 19
- D. 10
Correct answer: D. 10
The monotonic stack pops bars taller than the current one, and each popped bar's rectangle spans between its smaller neighbours. Heights 5 and 6 over two bars give 10; 12 misreads the width as 2 at height 6, 6 is the tallest bar alone and 19 sums every bar.
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 minimum number of swaps of ANY two (not necessarily adjacent) elements needed to sort the permutation [4, 3, 2, 1] into…
- How many inversions (pairs i < j with a[i] > a[j]) does the array [2, 4, 1, 3, 5] contain?
- The array [5, 1, 6, 2, 7, 3, 8] must be made strictly increasing by deleting as few elements as possible. How many deletions are needed?
- How many pairs i < j in [2, 3, 4, 6, 9] have gcd(a[i], a[j]) = 1?
- What is the sum of gcd over all contiguous subarrays of [4, 6, 8, 9]?
- How much rain water is trapped between bars of heights [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]?