Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: A bank processes queued withdrawals of 40, 25, 60, 15, 30 from a balance of 100. Each withdrawal is processed only if the current balance covers it; otherwise it is skipped (not retried). What is the final balance?
- A. 35
- B. 30
- C. -70
- D. 20
Correct answer: D. 20
100 − 40 = 60, − 25 = 35, 60 skipped, − 15 = 20, 30 skipped, so 20. Stopping at the first skip leaves 35, processing smallest first leaves 30, and no balance check gives −70.
More Coding Interview Problems questions
- Problem: The Z-array of "aaabaab" is computed (z[0] is the full length by convention). What is the sum of z[1] through z[6]?
- Problem: The string "aaaa" has how many distinct palindromic substrings (counting each distinct string once, of any length ≥ 1)?
- Problem: In the tree with edges 1-2, 1-3, 2-4, 2-5, 3-6, 3-7, what is the number of leaves (nodes with degree 1)?
- Problem: The subset-sum DP over the values [2, 3, 7, 8, 10] asks: how many subsets have sum exactly 11? The empty subset has sum 0 and is…
- Problem: The array [10, 20, 30, 40, 50] is searched for the first index i whose value is strictly greater than the average of all elements…
- Problem: Bob has the numbers 1 to 10 written on a board. He repeatedly erases the two largest numbers and writes their difference. After 9…