Problem · Array

Count Subarrays with Bitwise OR Present

HardMicrosoftOA
See Microsoft hiring insights

Given an array of size up to 100000, count the number of subarrays for which the bitwise OR of all the elements of the subarray is present in that subarray itself. We need an efficient solution with O(n) or O(nlogn) time complexity.

Examples
01 · Example 1
arr = [1, 6, 7]
return = 5
🦇
02 · Example 2
arr = [2, 4, 7]
return = 5
🦕
More Microsoft problems
drafts saved locally
public int countSubarraysWithBitwiseORPresent(int[] arr) {
  // write your code here
}
arr[1, 6, 7]
expected5
sign in to submit