Data Structures & AlgorithmsHardGATE CS · DSA
Lines of heights [6, 9, 5, 6, 8, 1, 8, 3, 5] stand at x = 0, 1, …, 8. Two pointers find the pair of lines that, with the x-axis, holds the most water (area = min(h[i], h[j]) × (j − i)). What is that maximum area?
- A. 39
- B. 40
- C. 14
- D. 72
Correct answer: B. 40
Start with the widest pair and always move the pointer at the shorter line inward (the taller one cannot do better with a narrower width). The best area is 40.
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
- Exponential search: double the bound i (1, 2, 4, …) until a[i] ≥ key or i passes the end, then binary-search the last range. How many…
- 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][0] = 5…
- A circular queue in an array of size 7 keeps one slot empty to tell full from empty (front = rear means empty; (rear + 1) mod 7 = front…
- Count distinct values in every window of size k with a frequency map. What is printed? python from collections import Counter a, k = [4…
- What is the minimum number of stacks needed to evaluate a fully parenthesised infix expression directly (without converting it first)…
- Merge sort and quick sort are compared. Which statement is correct?