Count Good Subarrays

You are given an integer array nums.

A subarray is called good if the bitwise OR of all its elements is equal to at least one element present in that subarray.

Return the number of good subarrays in nums.

Here, the bitwise OR of two integers a and b is denoted by a | b.

Example 1
Inputnums = [4,2,3]
Output4
The good subarrays are [4], [2], [3], and [2, 3], so the answer is 4.
Example 2
Inputnums = [1,3,1]
Output6
Every subarray has a bitwise OR that is present in that subarray, so all 6 subarrays are good.

Constraints

  • 1 <= nums.length <= 10^5
  • 0 <= nums[i] <= 10^9

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate