Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA
Problem: Find the maximum amount of water held between two vertical lines of heights [1, 8, 6, 2, 5, 4, 8, 3, 7] (the water is limited by the shorter line, and the width is the index difference).
- A. 49
- B. 56
- C. 8
- D. 64
Correct answer: A. 49
Two pointers move the shorter line inward; the best pair is heights 8 and 7 at indices 1 and 8: min(8, 7) × 7 = 49. Using the taller line (or width j − i + 1) gives 56, the two outer lines give 1 × 8 = 8, and 64 multiplies the tallest height by the full width.
More Coding Interview Problems questions
- Problem: What is the largest integer x with x² ≤ 2,000,000,000 (the floor of the square root of 2 × 10⁹)?
- Problem: What is the sum of the first 50 odd positive integers (1 + 3 + 5 + … + 99)?
- Problem: In a binary-tree-free DFS on the undirected graph with edges 0-1, 0-2, 1-3, 2-4, 3-4, 4-5, starting from vertex 0 and always…
- Problem: What does the following print? python print(sorted(['b', 'B', 'a', 'A']))
- Problem: Selection sort is run on [4, 3, 2, 1] in the usual way (for each position, find the minimum of the unsorted suffix and swap it…
- Problem: A Rule 90 cellular automaton on an infinite line starts with a single live cell. A cell's next state is 1 exactly when its two…