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?
- A. 150
- B. 155
- C. 175
- 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
- Problem: A water-jug problem: a 3-litre jug and a 5-litre jug, both empty, and unlimited water. Allowed actions: fill a jug fully, empty a…
- Problem: The string "PAYPALISHIRING" is written in a zigzag on 3 rows (letters go down the rows in a zigzag, then the rows are read left…
- Problem: How many ordered pairs (i, j) with 1 ≤ i < j ≤ 10 satisfy i XOR j = 3?
- Problem: In how many ways can 100 be written as a sum of two perfect squares x² + y² with 0 ≤ x ≤ y (unordered, non-negative)?
- Problem: How many prime numbers are there in the range 1 to 200 (inclusive)?
- Problem: Compute σ(360), the sum of all positive divisors of 360.