Data Structures & AlgorithmsHardFlipkart/Uber OA · placement
Bars of width 1 have heights [7, 3, 3, 6, 1, 3, 7, 1, 1]. How many units of rain water are trapped between them (two-pointer method with left-max and right-max)?
- A. 19
- B. 42
- C. 20
- D. 18
Correct answer: A. 19
Water above bar i is min(max to its left, max to its right) − h[i], never negative. Summing gives 19; filling every bar to the global maximum overestimates it.
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
- Bubble sort (ascending; each pass compares adjacent pairs left to right and swaps if out of order) is applied to [49, 52, 21, 37, 35, 19…
- Z-array: z[i] is the length of the longest common prefix of s and s[i:], with z[0] defined as 0. What is printed? python s = "aaaaabaaa" z…
- A Python 2-D list is created two ways and one cell is set. What is printed? python a = [[0] 3] 3 b = [[0] 3 for in range(3)] a[0][1] = 5…
- An array of size 9 holds the numbers 1..9, except that one number is missing and one number appears twice: [6, 5, 1, 3, 4, 7, 2, 8, 2]…
- Overlapping versus non-overlapping substring counts. What is printed? python s, p = "aababaaabbba", "aba" over = sum(1 for i in…
- 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…