Problem · Array

Count Subarrays with Bitwise OR Present

Learn this problem
HardMicrosoft logoMicrosoftOA
See Microsoft hiring insights

Problem statement

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.

Function

countSubarraysWithBitwiseORPresent(arr: int[]) → long

Examples

Example 1

arr = [1, 6, 7]return = 5
🦇

Example 2

arr = [2, 4, 7]return = 5
🦕

Constraints

  • 1 <= arr.length <= 100,000
  • Each element fits in a signed 32-bit integer.

More Microsoft problems

drafts saved locally
public long countSubarraysWithBitwiseORPresent(int[] arr) {
  // write your code here
}
arr[1, 6, 7]
expected5
checking account