Ctrl K

Striped Bits

Easy
Call a positive integer striped if any two neighbouring digits of its binary form differ, so ones and zeros alternate like stripes. You are given number. Return True if it is striped and False otherwise.
Example 1
number=21 → True

21 is 10101: ones and zeros strictly alternate.

Example 2
number=12 → False

12 is 1100: two ones in a row break the stripes.

Example 3
number=2 → True

2 is 10, two different digits, so it alternates.

Constraints
  • 1 ≤ number ≤ 2³¹ − 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSum of Binary Strings EasyThe Unpaired Value EasyFlip the Bit Order EasyCount the Set Bits EasySize of a Packed Tree Easy
loading Python…
Input
number=21
Expected
True

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