Skip to main content
Back to problems
#3894
Easy Algorithms

Traffic signal color

83.1% acceptance
May 13, 2026
26
5
You are given an integer timer representing the remaining time (in seconds) on a traffic signal. The signal follows these rules: If timer == 0, the signal is "Green" If timer == 30, the signal is "Orange" If 30 < timer <= 90, the signal is "Red" Return the current state of the signal. If none of the above conditions are met, return "Invalid".

Solution

Rust
Time O(1)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn traffic_signal(timer: i32) -> String {
    if timer == 0 { "Green".to_string() }
    else if timer == 30 { "Orange".to_string() }
    else if timer > 30 && timer <= 90 { "Red".to_string() }
    else { "Invalid".to_string() }
  }
}