Google | OA 2021 | Lost friendships
Anonymous User
219

The question is given two arrays A and B of length N. Following operations are performed on array:

  1. For the ith operation, take two numbers X and Y
  2. X equals A[i] or XOR of A[i] with any of its previously lost elements.
  3. Y equals B[i] or XOR of B[i] with any of its previously lost elements.
  4. If X > Y, array B loses its ith element.
  5. If X < Y, array A loses its ith element.
  6. 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?

Comments (2)