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?

  1. A. 35
  2. B. 30
  3. C. -70
  4. 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

Exams that ask this topic