LeetCode Courses 3894. Traffic Signal Color
LeetCode

3894. Traffic Signal Color

We work through an if/elif ladder, then tighten the range checks using Python's chained-comparison syntax. The `a <= x < b` form replaces clumsy boolean ANDs anywhere you have ranges.

1 chapter Beginner Written walk-through Updated 14 May 2026 Phil · @FirnoxGames
Free

Free for everyone. No account needed.

Start reading →

What you'll learn

1 3894. Traffic Signal Color 📖 4 min read

We work through an if/elif ladder, then tighten the range checks using Python's chained-comparison syntax. The `a <= x < b` form replaces clumsy boolean ANDs anywhere you have ranges.

In this chapter
  1. Problem
  2. If statements
  3. Double inequality

Problem

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

Included with this course
📖Written version of every chapter