

Two subarrays are distinct when they have at least one different element.
If ARR = [3,2,3], and K = 1
then there are 4 subarrays with at most K odd elements:
[3], [3,2], [2,3],[2]
The first line of input contains a single integer T, representing the number of test cases or queries to be run.
The first line of each test contains single space-separated two integers N and K.
The second line of each test contains N space-separated integers, denoting the elements of array ARR.
For each test case, print the number of distinct subarrays with at most K odd elements.
1 <= T <= 10
1 <= N <= 3000
1 <= K <= N
1 <= ARR[i] <= 10^9
Time Limit: 1sec
You do not need to print anything, it has already been taken care of. Just implement the given function.
In this solution, we try to generate all subarrays and check if the subarray contains at most K odd elements or not. Also, we will build a HashSet of the subarray to check if any subarray is already in the HashSet or not. If the subarray contains at most K odd elements and it is not present in the HashSet then we will increment our answer by 1.
Steps:
The idea is here to maintain a sliding window that will contain at most K odd elements and if odd elements in the window become greater than K then we will pop elements from the front until we will make a window in which will contain at most K odd elements.
In this approach, we will use a suffix array and longest common prefix(LCP) array to count unique subarrays which contain no more than k odd elements. Also, we will optimize the solution with the help of the boundaryArray that will tell us whether or not it will exceed k odd elements after the addition of more elements in the current subarray.
Boundary Array: Boundary array will store right boundary for each index for at most k odd elements
Suffix Array: Suffix Array will store all the sorted suffixes of array ‘ARR’’.
LCP array: Each index of LCP array will store how many elements two sorted suffixes have in common.
Unique subarrays = (total subarrays having k unique elements - duplicates), where
duplicates = sum of elements in LCP array.