lamps and an integer need. Call a contiguous non-empty stretch of the array bright if the bitwise OR of all its elements is at least need.
Return the length of the shortest bright stretch, or -1 if there is none.lamps=[4, 1, 2, 5], need=7 → 2
No single value reaches 7, but the stretch [2, 5] gives 2 | 5 = 7, so the answer is 2.
lamps=[1, 2, 4], need=7 → 3
Only the whole array gives 1 | 2 | 4 = 7, so the answer is 3.
lamps=[3, 3], need=4 → -1
The bitwise OR of any elements is 3, which never reaches 4, so the answer is -1.
len(lamps) ≤ 50lamps[i] ≤ 10⁹need ≤ 10⁹lamps=[4, 1, 2, 5], need=7
2
Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.