Data Structures & AlgorithmsVery hardGATE CS · Product placement
Bars of width 1 have heights [2, 3, 1, 5, 2, 1, 1, 6]. What is the area of the largest rectangle that fits under the histogram (computed with a stack of increasing heights)?
- A. 7
- B. 6
- C. 12
- D. 8
Correct answer: D. 8
For every bar, extend to the nearest smaller bar on each side; the best height × width is 8. The tallest bar alone or the full-width minimum strip are smaller.
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
- For an array of n elements, how many contiguous subarrays are there, and how many subsequences (including the empty one)?
- A monotonic deque reports the maximum of every window of size 3 in [19, 6, 7, 16, 10, 2, 12, 8, 17]. What is the SUM of all reported…
- Two pointers start at both ends of the sorted array [3, 4, 5, 6, 8, 17, 18, 23, 26, 27]. How many pairs (i < j) have a[i] + a[j] ≤ 40?…
- What does this loop-counting code print? (Python) python n, c = 20, 0 i = n while i > 0: for j in range(i): c += 1 i //= 2 print(c)
- Rabin–Karp with base 10 and a deliberately small modulus counts true matches and spurious hits (hash equal, text different). What is…
- Using a sliding window with a last-seen index map, what is the length of the longest substring of "beeebdddcbadad" with all characters…