Ctrl K

One Lit Stretch

Easy
A row of street lamps runs along a road. The string lamps describes them from left to right: '1' means the lamp is on, '0' means it is off. The first lamp is always on. Return True if all the lit lamps form one unbroken stretch, and False if some unlit lamp sits between lit ones.
Example 1
lamps="111000" → True

The first three lamps are lit in a row and the rest are off: one stretch.

Example 2
lamps="1101" → False

An unlit lamp sits between lit ones, so there are two stretches.

Example 3
lamps="1" → True
Constraints
  • 1 ≤ len(lamps) ≤ 100
  • Every character of lamps is '0' or '1'
  • lamps[0] == '1'
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
lamps="111000"
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 110 tests on the server, hidden ones included.