All problems
0933EasyMathStringSimulation

Which Light Is Showing

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3894Traffic Signal Color

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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