FunctionRacerProblemsRace

XOR Up To N

EasyBitsPython, JavaScript, TypeScript, Java, C++

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

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