primes. For each primes[i], find the smallest non-negative integer a such that a OR (a + 1) == primes[i], where OR is the bitwise OR of a number and the number right after it.
If no such a exists, put -1 in that position. Return the array of answers, of the same length and in the same order.primes=[19, 2, 23] → [17, -1, 19]
19 = 10011₂: 17 OR 18 = 10001₂ OR 10010₂ = 10011₂ = 19, and nothing smaller works. For 2 there is no answer: one of two neighbouring numbers is odd, so a OR (a + 1) is always odd, hence -1. For 23 = 10111₂ the answer is 19: 19 OR 20 = 23.
primes=[3, 31] → [1, 15]
1 OR 2 = 3, and 15 OR 16 = 11111₂ = 31.
primes=[5] → [4]
primes[i] is a prime numberprimes=[19, 2, 23]
[17, -1, 19]
Run checks the first 3 tests in your browser. Submit checks all 229 tests on the server, hidden ones included.