java.lang.Object
g3201_3300.s3209_number_of_subarrays_with_and_value_of_k.Solution

public class Solution extends java.lang.Object
3209 - Number of Subarrays With AND Value of K.

Hard

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:

Input: nums = [1,1,1], k = 1

Output: 6

Explanation:

All subarrays contain only 1’s.

Example 2:

Input: nums = [1,1,2], k = 1

Output: 3

Explanation:

Subarrays having an AND value of 1 are: [ 1 ,1,2], [1, 1 ,2], [ 1,1 ,2].

Example 3:

Input: nums = [1,2,3], k = 2

Output: 2

Explanation:

Subarrays having an AND value of 2 are: [1, 2 ,3], [1, 2,3 ].

Constraints:

  • 1 <= nums.length <= 105
  • 0 <= nums[i], k <= 109
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    countSubarrays(int[] nums, int k)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countSubarrays

      public long countSubarrays(int[] nums, int k)