Ctrl K

Is the Last Signal Short?

Easy
An old lighthouse sends messages using two kinds of signals. A short signal is written as a single digit 0. A long signal is written as two digits and always starts with a one: 10 or 11. The tape pulses records several signals in a row, with no separators. The tape always ends with a zero, and there is exactly one way to split it into signals. Return true if the last signal on the tape is short, and false if the final zero is the second half of a long signal.
Example 1
pulses=[1, 1, 0] → True

The tape reads only one way: 11 is a long signal, then 0 is a short one. The last signal is short.

Example 2
pulses=[0, 1, 0] → False

First a short 0, then 10 is a long signal that swallows the final zero. The answer is false.

Example 3
pulses=[0] → True

The only signal is a short 0.

Constraints
  • 1 ≤ pulses.length ≤ 1000
  • pulses[i] is 0 or 1
  • The last element of pulses is 0
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasySqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasySlot on a Sorted Shelf EasyAdd One to a Digit Array Easy
loading Python…
Input
pulses=[1, 1, 0]
Expected
True

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