> // Return total count of subarrays having XOR of
> // elements as given value m
> return ans;
You only get 2, because that's all you return.
If you want the rest of the information like
- length 3 starting at index 0
- length 4 starting at index 1
Then just return mp or whatever - it's your code.
Plus, you leak memory by never freeing xorArr.
Edit:
Whatever, you're just another chancer trying to cheat on some programming contest.
Original code here:
https://www.geeksforgeeks.org/count-number-subarrays-given-xor/
1 2 3 4 5 6 7 8 9 10 11 12 13
|
$ diff -b 1st_file.txt 2nd_file.txt
0a1,3
> // C++ Program to count all subarrays having
> // XOR of elements as given value m with
> // O(n) time complexity.
53c56
< int arr[] = { 2,5,7,1,3 };
--
> int arr[] = { 4, 2, 2, 6, 4 };
55c58
< int m = 0;
--
> int m = 6;
|
All you did was rip off the initial comment and change the array of numbers.
If you'd actually WRITTEN that code yourself, you wouldn't be asking such a basic question like "but I also need the length". If you knew how the code actually worked (because you'd written it), then you would already know that.