This is the Question:
https://practice.geeksforgeeks.org/problems/find-the-odd-occurence/0
Given an array of positive integers where all numbers occur even number of times except one number which occurs odd number of times. Find the number.
Input can range from
1 ≤ T ≤ 100 : Test Cases
1 ≤ N ≤ 107 : Number of inputs
1 ≤ A[i] ≤ 106 : Inputs
Example:
Input:
1
5
8 4 4 8 23
Output:
23
This is code:
class GFG
{
public static void main (String[] args)
{
//code
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int N = sc.nextInt();
int count = 0;
for(int j = 0; j<N; j++){
int in = sc.nextInt();
count =count^in;
}
System.out.println(count);
}
}
}
My question is, The OJ took 2.5s to execute it and other people did this in significantly less time than mine. Some did it in 0.3s. And that too including inputting the numbers in an array and then iterating through them.
Why is that, Is this because of OJ or what, I didn't get it? Also I did the submission several times just to make sure there if there was a fault but all the time it took more than 2.5s.