Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: A traffic light cycles green for 30 s, then yellow for 5 s, then red for 25 s, starting at time 0 with green. How many whole seconds t in [0, 300) (t integer) fall in the green phase?

  1. A. 150
  2. B. 155
  3. C. 175
  4. D. 125

Correct answer: A. 150

The cycle is 30 + 5 + 25 = 60 s and green covers t mod 60 in 0..29, so 300 s hold 5 × 30 = 150 green seconds. Counting t mod 60 ≤ 30 gives 155, dropping the yellow phase (a 55 s cycle) gives 175, and 125 counts the red seconds.

More Coding Interview Problems questions

Exams that ask this topic