Count Subarrays with XOR K
Hard Problems: N-Sum & Hashing DSA practice problem on Onlearn.
Difficulty: hard.
Topics: Find number of subarrays with bitwise XOR equal to k, Arrays, XOR, Subarray, Hashing, Map, Time Complexity, Space Complexity, Big O Notation, Loops, Prefix Sum, Bitwise Operations, bit manipulation, brute force, subarray, hash map, time complexity analysis, Prefix XOR.
Given an array of integers A and an integer k, find the total number of subarrays whose elements' bitwise XOR sum is equal to k. Input Specification: The first line contains an integer N, the size of the array A. The second line contains N space separated integers representing the elements of array A. The third line contains an integer k. Output Specification: Print a single integer, the total number of subarrays whose elements' bitwise XOR sum is equal to k. Sample Test Cases: Example 1: Input: A = [4, 2, 2, 6, 4], k = 6 Output: 4 Explanation: The subarrays having XOR of their elements as 6 are [4, 2], [4, 2, 2, 6, 4], [2, 2, 6], [6] Example 2: Input: A = [5, 6, 7, 8, 9], k = 5 Output: 2 Explanation: The subarrays having XOR of their elements as 5 are [5] and [5, 6, 7, 8, 9]