FunctionRacerProblemsRace

Different ORs of Stretches

MediumBitsPython, JavaScript, TypeScript, Java, C++

Take a stretch of nums (one or more items next to each other) and combine all its items with bitwise OR (|). Do this for every stretch.

Return how many different results there are.

Example 1

nums [2,1,5]
returns 5

The single items give 2, 1 and 5. Then 2 | 1 = 3, 1 | 5 = 5 again, and 2 | 1 | 5 = 7. That is five different values.

Example 2

nums [4,4,4]
returns 1

Every stretch gives 4.

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