FunctionRacerProblemsRace

Bitwise OR of a Range

MediumBitsPython, JavaScript, TypeScript, Java, C++

Return the value obtained by combining every integer from lo to hi (both included) with bitwise OR (|). A bit of the answer is 1 exactly when at least one integer in the range has that bit set. The range can hold about two billion numbers, so a loop over all of them is too slow.

Example 1

lo 5
hi 7
returns 7

5 | 6 | 7 is 101 | 110 | 111, which is 111, or 7.

Example 2

lo 4
hi 6
returns 7

4 | 5 | 6 is 100 | 101 | 110, which is 111, or 7.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Bits problems