Data Structures & AlgorithmsHardGATE CS · TCS NQT
What is the area of the largest rectangle that fits in a histogram whose bar heights are 2, 1, 5, 6, 2, 3 (each bar has width 1)?
- A. 10
- B. 8
- C. 6
- D. 19
Correct answer: A. 10
The best rectangle spans bars 5 and 6 at height 5: area 10. A stack finds, for each bar, the widest span where it is the minimum. Height 2 over four bars gives 8, the tallest bar alone 6, and 19 is the total area of all bars.
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
- 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?
- 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…