values of n non-negative integers.
For every index i, consider the stretches that start at i and run to the right: values[i..j]. Their bitwise OR never decreases as j grows and peaks once the stretch reaches the end of the array, but that same peak is often reached earlier.
Return an array of length n whose entry i is the length of the shortest non-empty stretch starting at i whose bitwise OR equals the largest OR of any stretch starting at i.values=[4, 1, 0, 2, 6] → [4, 4, 3, 2, 1]
From index 0 the OR to the end is 7, and all three bits are only collected by the element 2, so the length is 4. From index 1 the bit 4 only shows up in the last element, so 4 again. Then [0, 2, 6] gives 3, [2, 6] gives 2 and [6] gives 1.
values=[0, 0] → [1, 1]
The best OR from any start is 0, which a single element already gives.
values=[5, 3] → [2, 1]
values=[4, 1, 0, 2, 6]
[4, 4, 3, 2, 1]
Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.