Show problems as
Classic problem #3894EasyMathStringSimulation

Traffic Signal Color

Real-world version: Which Light Is Showing
Tracked in this browser only
Read Traffic Signal Color on LeetCode(opens in a new tab)

The 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.

Python
def traffic_signal(timer: int) -> str:
Java
public String trafficSignal(int timer)