Data Structures & AlgorithmsVery hardProduct Company SDE · Amazon OA
Problem: Remove exactly 3 digits from the number "1432219" to make the smallest possible number (leading zeros are not allowed in the result). What is the resulting number?
- A. 1221
- B. 2219
- C. 1219
- D. 1432
Correct answer: C. 1219
A monotonic stack removes a digit whenever the next digit is smaller: 4 (before 3), 3 (before 2), then 2 (before 1), leaving 1219. Removing the three largest digits 4, 3, 9 gives 1221, deleting the first three digits gives 2219, and deleting the last three gives 1432.
More Coding Interview Problems questions
- 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…
- What does this program print? python n = 6 dp = [0] (1 << n) dp[0] = 1 for mask in range(1 << n): if dp[mask] == 0: continue for v in…