WORLD 8
BITS AND MATH
Treat a number as a row of switches: cancel pairs with XOR, clear bits one at a time.
STAGE 0 Bits and math tutorial
0:00 / 0:00
The move
Treat every number as a row of switches. XOR cancels pairs (x ^ x = 0), x & (x - 1) clears the lowest set bit, and shifts double or halve. Math tricks like sums and repeated squaring replace whole loops.
- Spot it
- Every number appears twice except one, count the 1 bits, power of two, no extra space, or a huge exponent.
- Cost
- Each bit operation is one step on a fixed-width number, so one pass is O(n) time and O(1) space.
20 STAGES
☆☆☆☆☆ Clear any 5 stages to beat this world, or all 20 for 100%.
EASY2:07Single Number
Bit manipulationLC 136▶ START
MEDIUM2:05Single Number II
Bit manipulationLC 137▶ START
MEDIUM2:08Single Number III
Bit manipulationLC 260▶ START
EASY2:09Number of 1 Bits
Bit manipulationLC 191▶ START
EASY2:11Hamming Distance
Bit manipulationLC 461▶ START
EASY2:05Counting Bits
Bit manipulationLC 338▶ START
MEDIUM2:08Gray Code
Bit manipulationLC 89▶ START
MEDIUM2:06Rotate Image
MatrixLC 48▶ START
MEDIUM2:11Spiral Matrix
MatrixLC 54▶ START
EASY2:05Missing Number
MathLC 268▶ START
MEDIUM2:07Pow(x, n)
Fast exponentiationLC 50▶ START
EASY2:10Sqrt(x)
Binary searchLC 69▶ START
EASY2:11Reverse Bits
Bit manipulationLC 190▶ START
MEDIUM2:07Sum of Two Integers
Bit manipulationLC 371▶ START
MEDIUM2:09Reverse Integer
MathLC 7▶ START
EASY2:09Palindrome Number
MathLC 9▶ START
EASY2:09Happy Number
Fast and slow pointersLC 202▶ START
EASY2:04Plus One
CarryLC 66▶ START
MEDIUM2:10Multiply Strings
CarryLC 43▶ START
MEDIUM2:09Bitwise AND of Numbers Range
Bit manipulationLC 201▶ START