XOR Up To N
Return the bitwise XOR (^) of all the integers from 0 to n, both included.
Example 1
n 5
returns 1
0^1^2^3^4^5 = 1.
Example 2
n 3
returns 0
0^1^2^3 = 0.
Constraints
0 <= n <= 10**4
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Bits problems
- Bitwise OR of a RangeMedium
- Different ORs of StretchesMedium
- Differing Bits Over All PairsMedium
- Flips to Make OR EqualMedium
- Insert a Bit FieldMedium
- Longest Pair With No Shared LetterMedium
- Next Gray CodeMedium
- Subsets With a Target XORMedium