Trains the technique from
LeetCode 3894Traffic Signal ColorThis 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".
Example 1
Thirty-four seconds in, the green ended at thirty and the amber runs to thirty-five, so the amber is showing.
Example 2
A thousand seconds is forty seconds into a later cycle, which falls in the red stretch.
Example 3
A hundred and forty-eight seconds is twenty-eight into a later cycle, so the green is still showing.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def traffic_signal(timer: int) -> str:public String trafficSignal(int timer)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.