Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: Cars pass a toll booth at times 2, 5, 6, 10, 11, 15 (minutes). A car may pass only if at least 3 minutes have elapsed since the previous car that passed. How many cars pass?

  1. A. 5
  2. B. 3
  3. C. 4
  4. D. 6

Correct answer: C. 4

Greedy acceptance in time order: car at 2 passes, car at 5 passes (gap 3), car at 6 is too soon, car at 10 passes, car at 11 is too soon, and car at 15 passes, giving four cars.

More Coding Interview Problems questions

Exams that ask this topic