Number of Subarrays With AND Value of K

Given an array of integers nums and an integer k, return the number of subarrays of nums where the bitwise AND of the elements of the subarray equals k.

Example 1
Inputnums = [1,1,1], k = 1
Output6
All subarrays contain only 1's.
Example 2
Inputnums = [1,1,2], k = 1
Output3
Subarrays having an AND value of 1 are [1,1,2] using the first element, [1,1,2] using the second element, and [1,1,2] using both first two elements.

Constraints

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

Asked at 1 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