Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional
Problem: Water fills a 1-dimensional container with walls of heights [4, 1, 3, 1, 2]. Each cell holds water up to the minimum of the tallest wall on its left and right, minus its own height. What is the total water held?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Each cell's water level is limited by the lower of its two side maxima. The cells at indices 1 and 3 hold 2 and 1 units respectively, so the total is 3.
More Coding Interview Problems questions
- Problem: Compute the sum of all integers from 1 to 999 whose digits are all odd.
- Problem: What is the number of ways to climb 8 steps when each move is 1, 2 or 4 steps, counted as ordered sequences?
- Problem: The array [1, 2, 3, 4, 5, 6, 7, 8, 9] is split into 3 consecutive groups of equal length. What is the sum of the middle group?
- Problem: The product of the numbers from 1 to 10, divided by the product of the numbers from 1 to 7, is what value?
- Problem: A string is "xoxoxox". How many substrings of length 3 are equal to "xox"?
- Problem: Consider the graph on vertices 1–6 with edges 1-2, 2-3, 3-4, 4-1, 5-6. What is the size of its largest connected component?