Along a stretch of coastline, n harbor beacon towers stand in a row. Each tower continuously broadcasts a signal code — a non-negative integer whose bits mark which light channels the tower currently has switched on. Between every two neighboring towers sits a relay pole, and every relay pole must light any channel that either of its two neighboring towers has lit, so its code is the bitwise OR of the two towers' codes. Given the beacon codes in order along the coast, report the code broadcast by every relay pole, from the one between the first and second tower through the one between the second-to-last and last tower.
Print n-1 space-separated integers on a single line: the relay code between tower i and tower i+1, for i = 1 to n-1, in that order.
Example 1
Input
4 5 3 9 2
Expected
7 11 11
Explanation
Codes are 5 (101), 3 (011), 9 (1001), 2 (0010). Relay 1 ORs towers 1 and 2: 101|011=111=7. Relay 2 ORs towers 2 and 3: 0011|1001=1011=11. Relay 3 ORs towers 3 and 4: 1001|0010=1011=11. Output: 7 11 11.
Example 2
Input
2 0 0
Expected
0
Explanation
There is only one relay pole, between the two towers, both broadcasting 0: 0|0=0. Output: 0.
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 →