The question is given two arrays A and B of length N. Following operations are performed on array:
- For the ith operation, take two numbers X and Y
- X equals A[i] or XOR of A[i] with any of its previously lost elements.
- Y equals B[i] or XOR of B[i] with any of its previously lost elements.
- If X > Y, array B loses its ith element.
- If X < Y, array A loses its ith element.
- If X = Y both elements live.
We need to count the number of lost elements of array B after N operations
Example:
Input:
N = 4, A[] = {4, 8, 6, 7}, B[] = {2, 8, 10, 5}
Output:
2
I mentioned the brute force solution only. He it can much more optimized. Can anyone provide an optimized solution for this?