human
Count of subarrays of size K with elements having even frequencies | Function to return count of required subarrays.
If K is odd.
Not possible to have any such subarrays.
Stores the starting index of every subarrays.
Stores the count of required subarrays.
Stores Xor of the current subarray ..
Xor of first subarray of size K.
If all elements appear even number of times , increase the count of such subarrays.
Remove the starting element from the current subarray.
Traverse the array for the remaining subarrays.
Update Xor by adding the last element of the current subarray.
Increment i.
If currXor becomes 0 , then increment count.
Update currXor by removing the starting element of the current subarray.
Return count.
Driver Code"
Solution in Python:
 ... Give me a code to count of subarrays of size K with elements having even frequencies and the other steps required?
assistant
#Here is code to count of subarrays of size K with elements having even frequencies and the other steps required.
 def countSubarray ( arr , K , N ) :
	if ( K % 2 != 0 ) :
		return 0
	if ( N < K ) :
		return 0
	start = 0
	i = 0
	count = 0
	currXor = arr [ i ]
	i += 1
	while ( i < K ) :
		currXor ^= arr [ i ]
		i += 1
	if ( currXor == 0 ) :
		count += 1
	currXor ^= arr [ start ]
	start += 1
	while ( i < N ) :
		currXor ^= arr [ i ]
		i += 1
		if ( currXor == 0 ) :
			count += 1
		currXor ^= arr [ start ]
		start += 1
	return count
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 4 , 4 , 2 , 2 , 4 ]
	K = 4
	N = len ( arr )
	print ( countSubarray ( arr , K , N ) )