#898

Bitwise ORs of Subarrays

specialist · 775 · lc medium +31 · verified · 56.8% accepted · 1,961 likes · top 52%

Description

Given an integer array arr, determine how many distinct values arise as the bitwise OR of some non-empty contiguous subarray. A single-element subarray contributes its own value; longer subarrays OR-combine all included elements.

Example 1:

Input: arr = [0]
Output: 1
Explanation: There is only one possible result: 0.

Example 2:

Input: arr = [1,1,2]
Output: 3
Explanation: The possible subarrays are [1], [1], [2], [1, 1], [1, 2], [1, 1, 2].
These yield the results 1, 1, 2, 1, 3, 3.
There are 3 unique values, so the answer is 3.

Example 3:

Input: arr = [1,2,4]
Output: 6
Explanation: The possible results are 1, 2, 3, 4, 6, and 7.

Code

1
2
3