FunctionRacerProblemsRace

Undo the XOR Chain

MediumBitsPython, JavaScript, TypeScript, Java, C++

A secret list holds the numbers 1 to n in some order, and n is odd. You only get links, where links[i] is the XOR (^) of items i and i + 1 of the secret list.

Return the secret list. It is always the only one that fits.

Example 1

links [1,2]
returns [2,3,1]

2 ^ 3 = 1 and 3 ^ 1 = 2. No other order of 1, 2, 3 gives these links.

Example 2

links [5,4,6,1]
returns [4,1,5,3,2]

4 ^ 1 = 5, 1 ^ 5 = 4, 5 ^ 3 = 6 and 3 ^ 2 = 1.

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