flags is a set of enabled settings packed into bits: a one in the binary form means the matching setting is on.
For every pair of neighbouring items, build the merged set, where a setting is on if it is on in at least one of the two neighbours. That is the bitwise OR (|).
Return a list of length len(flags) - 1 whose item at position i is flags[i] | flags[i + 1].flags=[2, 5, 8] → [7, 13]
2 | 5 = 0b010 | 0b101 = 0b111 = 7, and 5 | 8 = 0b0101 | 0b1000 = 0b1101 = 13.
flags=[6, 6] → [6]
One pair of neighbours, and 6 | 6 = 6.
flags=[0, 9, 0, 1] → [9, 9, 1]
0 | 9 = 9, 9 | 0 = 9, 0 | 1 = 1.
flags[i] ≤ 10⁹flags=[2, 5, 8]
[7, 13]
Run checks the first 3 tests in your browser. Submit checks all 107 tests on the server, hidden ones included.