Ctrl K

Ones on Even and Odd Places

Easy
You are given a positive integer number. Write it in binary and number its bits from right to left starting at zero: the lowest bit is position 0, the next one is position 1, and so on. Return a list of two numbers: how many ones sit at even positions and how many sit at odd positions.
Example 1
number=21 → [3, 0]

21 in binary is 10101. Its ones sit at positions 0, 2 and 4, all even, and there are none at odd positions.

Example 2
number=12 → [1, 1]

12 is 1100: ones at positions 2 and 3, one even and one odd.

Example 3
number=1 → [1, 0]
Constraints
  • 1 ≤ number ≤ 1000
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
[3, 0]

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