Data Structures & AlgorithmsVery hardProduct Company SDE · ICPC regional
Problem: Find the area of the largest rectangle in a histogram with bar heights [2, 1, 5, 6, 2, 3] (each bar has width 1).
- A. 6
- B. 10
- C. 12
- D. 8
Correct answer: B. 10
A monotonic stack finds the best rectangle over bars 5 and 6: height 5 × width 2 = 10. The tallest single bar gives 6, assuming both of those bars reach 6 gives 12, and spreading height 2 over bars 5, 6, 2, 3 gives 8.
More Coding Interview Problems questions
- Problem: Remove exactly 3 digits from the number "1432219" to make the smallest possible number (leading zeros are not allowed in the…
- Problem: How many trailing zeros does 1000! have in base 10?
- Problem: The string "BANANA" has how many distinct arrangements of its letters (letters are identical when they match)?
- Problem: For the word-count test: how many distinct strings can be formed by rearranging "AABBCCD" so that no two identical letters are…
- Problem: A game uses 5 players in a circle numbered 1 to 5. The player with the ball passes it 3 positions clockwise each turn (the ball…
- What does this program print? python a = [4, 1, 3, 2] best = 0 for i in range(len(a)): for j in range(i + 1, len(a) + 1): best = max(best…