Different ORs of Stretches
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
1 <= len(nums) <= 3000 <= nums[i] < 2**30
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Bits problems
- Differing Bits Over All PairsMedium
- Flips to Make OR EqualMedium
- Insert a Bit FieldMedium
- Longest Pair With No Shared LetterMedium
- Next Gray CodeMedium
- Subsets With a Target XORMedium
- The One Not TripledMedium
- Two Unpaired NumbersMedium