Along a straight corridor there are n lanterns in a row, each configured with a secret numeric glow-code. A sensor mounted between each pair of adjacent lanterns can only measure the bitwise XOR of the two codes it sits between, never either code directly, producing a log with n - 1 entries. Separately, before the sensors were installed, a technician wrote down the exact glow-code of the very first lantern. Using the sensor log and that one recorded value, recover the glow-code of every lantern in order.
m, the number of sensor-log entries (m = n - 1, where n is the number of lanterns).m integers, the sensor log, where the i-th value (1-indexed) equals the bitwise XOR of the glow-codes of lantern i and lantern i+1.first, the recorded glow-code of the first lantern.Print n integers separated by single spaces on one line: the recovered glow-code of every lantern, from the first to the last.
Example 1
Input
4 1 2 3 1 1
Expected
1 0 2 1 0
Explanation
Start with lantern 1's code = 1. Lantern 2's code = 1 XOR 1 = 0. Lantern 3's code = 0 XOR 2 = 2. Lantern 4's code = 2 XOR 3 = 1. Lantern 5's code = 1 XOR 1 = 0. Output: 1 0 2 1 0.
Example 2
Input
1 7 5
Expected
5 2
Explanation
Lantern 1's code = 5. Lantern 2's code = 5 XOR 7 = 2. Output: 5 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →