⌘K
Flycodx

Calculate Traffic Signal Green Duration

Calculate Traffic Signal Green Duration

MediumStrings0% accepted

Pune traffic signals encode timing sequences as 'R30Y5G45' meaning Red for 30s, Yellow for 5s, Green for 45s. Colors are followed by duration in seconds. Ravi needs to find the total seconds the signal displays green.

Approach

Given a traffic signal timing string with pattern COLOR+DURATION repeated (e.g., 'R30Y5G45R30Y5G60'), calculate the total seconds the signal is green by summing all 'G' durations.

Input

R30Y5G45

Output

45
solution.py
Loading editor...
Test 1
Test 2
Test 3

Press Run to test your custom input, or Submit to judge against all test cases.

Sign in to continue

Create a free account to run code, submit solutions and track progress.

  • Free forever — no credit card
  • 10+ languages with live execution
  • Points, streaks & leaderboards
Auto Save OnLn 1, Col 1Spaces: 4UTF-8LFPython 3