15. Count Subarrays with given XOR
β GFG solution to Count Subarrays with given XOR: count subarrays with specific XOR value using prefix XOR and hash map technique. π
π§© Problem Description
π Examples
Example 1
Input: arr[] = [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], and [6]. Hence, the answer is 4.Example 2
Input: arr[] = [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].
Hence, the answer is 2.Example 3
π Constraints
β
My Approach
Prefix XOR Technique
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated