values and a number target. A window is a non-empty run of consecutive elements values[l..r]. The value of a window is the bitwise OR of all its elements: values[l] OR values[l + 1] OR ... OR values[r].
Pick the window whose value is closest to target and return the smallest possible gap |target − window value|.values=[4, 1, 8, 2], target=6 → 1
The window [4, 1] gives 4 OR 1 = 5, while [4, 1, 8] already gives 13. No window gives exactly 6; the closest is 5, so the answer is |6 − 5| = 1.
values=[3, 5, 6], target=7 → 0
5 OR 6 = 7, exactly the target.
values=[16, 16], target=3 → 13
Every window gives 16, so the gap is 13.
values.length ≤ 10⁵values[i], target < 2³¹values=[4, 1, 8, 2], target=6
1
Run checks the first 3 tests in your browser. Submit checks all 127 tests on the server, hidden ones included.