I have done many submissions for this problem but getting TLE for all. The same code is accepted in Java. This is bit manipulation question with in which we are given two arrays with odd number of elements let's say A and B, we have to check and arrange array B such that A1^B1 = A2^B2 =...= An^Bn. To solve this first we have to xor all the elements of A and B to find the the number that can be the common xor value for all elements (e.g A1 ^ A2). After calculating the xor we have to XOR this value with all the elements of array A to find another array C. If array B contains all the elements of array C. Then array C is our answer, this is the array containing all elements of B whose XOR with corresponding item of array A return the same value for all elements. I just need to find out why I am getting TLE for my solution in C#.
My submissions link - https://www.codechef.com/status/XORGM,himanshu0786?sort_by=All&sorting_order=asc&language=All&status=13&Submit=GO
using System;
using System.Linq;
public class Test
{
public static void Main()
{
int N, noOfTestCases = int.Parse(Console.ReadLine());
string[] temp1, temp2;
while (noOfTestCases-- != 0)
{
N = int.Parse(Console.ReadLine());
temp1 = Console.ReadLine().Trim().Split(); //.Select(int.Parse).Take(N).ToArray();
temp2 = Console.ReadLine().Trim().Split(); //.Select(int.Parse).Take(N).ToArray();
int xor = 0;
int[] A = new int[N], B = new int[N], C = new int[N];
for (int i = 0; i < N; ++i)
{
A[i] = int.Parse(temp1[i]);
B[i] = int.Parse(temp2[i]);
xor ^= A[i] ^ B[i];
}
for (int i = 0; i < N; ++i)
{
C[i] = A[i] ^ xor;
}
if (B.Except(C).Any())
{
Console.WriteLine(-1);
}
else
{
foreach (var num in C)
{
Console.Write($"{num} ");
}
Console.WriteLine();
}
}
}
}