Data Structures & AlgorithmsHardGATE CS · TCS NQT
In the binary row [1, 1, 0, 1, 1, 1] treated as a histogram of height 1, what is the largest rectangle area?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
With every bar height 1, the largest rectangle is simply the longest run of ones, which is three here. The monotonic stack reproduces this, and summing all ones is a different 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
- What is the length of the shortest contiguous subarray of [5, 1, 4, 3, 2, 6, 7] whose sum is at least 15?
- In [6, 3, 6, 9, 3, 9, 9, 5, 5] exactly one value appears an odd number of times and every other value appears an even number of times…
- How many index pairs i < j in [12, 21, 30, 43, 66, 111, 3] have equal decimal digit sums?
- How many ordered index pairs (i, j) in [1, 3, 4, 7, 10, 12, 15] satisfy a[j] - a[i] = 3?
- How many integers from 1 to 10000 inclusive are multiples of 7 whose decimal digit sum is exactly 7?
- For "aabaabaa", how many indices i >= 1 have Z-function value exactly 2?