Data Structures & AlgorithmsHardGATE CS · TCS NQT
For the histogram [2, 1, 2], each bar i has a maximal rectangle width w_i: the number of consecutive bars around i (including i) that are at least as tall as bar i. What is the sum of the w_i?
- A. 6
- B. 5
- C. 4
- D. 7
Correct answer: B. 5
Bar 0 has width 1, bar 1 spans all three bars (width 3) and bar 2 has width 1, so the total is 5.
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 distinct value pairs (x, y) with x < y satisfy x + y = 6 among the values in [1, 2, 3, 4, 5, 5, 1]?
- What is the minimum number of cuts needed to split "racecarxyz" into pieces that are all palindromes?
- What is the smallest positive integer n such that 2^n is greater than 100000?
- For [3, 1, 4, 2], split into a non-empty prefix and a non-empty suffix. For each split compute (minimum of prefix) times (maximum of…
- A split point is an index i (1 ≤ i ≤ n−1) that divides [1, 2, 3, 3, 2, 1, 4, 2] into a left part a[0..i−1] and a right part a[i..n−1] with…
- What is the length of the longest contiguous subarray of [5, 3, -2, 8, -4, 6, 1, 7] whose sum is divisible by 5 (the empty sum 0 counts as…