FunctionRacerProblemsRace

Set Bit Positions

BeginnerBitsPython, JavaScript, TypeScript, Java, C++

Number the bits of the non-negative integer n from the right, starting at 0 for the lowest bit. Return the positions of all the bits of n that are 1, as a list in increasing order. For n = 0 return an empty list.

Example 1

n 10
returns [1,3]

10 is 1010 in binary, with 1 bits at positions 1 and 3.

Example 2

n 1
returns [0]

1 has a single 1 bit, at position 0.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Bits problems