Problem · Array
Count Subarrays with Bitwise OR Present
Learn this problemProblem 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[]) → longExamples
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.