Data Structures & AlgorithmsHardGoldman Sachs OA · LeetCode medium-hard
Heights [1, 6, 2, 6, 2, 5, 2, 2, 7] represent vertical lines at each index. What is the maximum water area (min(height) × horizontal distance) obtainable between any two lines?
- A. 2
- B. 40
- C. 42
- D. 8
Correct answer: C. 42
Checking all pairs (equivalently, the two-pointer sweep that moves the shorter boundary inward) finds the best area is 42, between indices 1 and 8. Only using the two outermost lines, 8, is not always optimal since a taller inner pair can win.
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
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- Elevation map [4, 5, 4, 4, 0, 1, 2, 1, 0, 2] (bar width 1). Using the two-pointer / prefix-max approach for trapping rain water, how much…
- A circular queue of capacity 4 starts empty and runs this sequence in order: enqueue(3), enqueue(6), enqueue(4), enqueue(7), dequeue()…
- The Boyer–Moore majority vote algorithm (candidate/counter, no verification pass) runs on [7, 5, 2, 5, 5, 5, 2, 7]. What candidate and…
- What does this loop-counting code print? (Python) python n, c = 45, 0 i = 1 while i < n: j = i while j < n: c += 1 j = 2 i += 1 print(c)
- Array [83, 87, 90, 43, 45, 48, 62, 75, 82] is a sorted array rotated at pivot 6. Using the standard O(log n) rotated-array binary search…