Traffic Signal Color
Real-world version: Which Light Is ShowingThe statement here is our own: the same inputs, outputs and technique.
A signal runs on a fixed cycle of sixty seconds: it shows green for the first thirty seconds, then amber for the next five, then red for the remaining twenty-five, and then begins again.
The cycle starts at second 0 with green just coming on. Given timer, the number of seconds since then, return which light is showing: "green", "amber" or "red".
Examples
Example 1
- Input
- timer = 34
- Output
- "amber"
Thirty-four seconds in, the green ended at thirty and the amber runs to thirty-five, so the amber is showing.
Example 2
- Input
- timer = 1000
- Output
- "red"
A thousand seconds is forty seconds into a later cycle, which falls in the red stretch.
Example 3
- Input
- timer = 148
- Output
- "green"
A hundred and forty-eight seconds is twenty-eight into a later cycle, so the green is still showing.
Constraints
- 0 <= timer <= 1000
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def traffic_signal(timer: int) -> str:public String trafficSignal(int timer)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 13 test cases: 13 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's