While compiling it I keep getting the right answer but when I submit none of the test cases have passed.
Here’s my code - https://ide.codingblocks.com/s/245834
Wrong answer in unique numbers - ii question
code is fine . check this condition before syso line
if(x>y)
System.out.println(y+ " " + x);
else
System.out.println(x + " " + y);
import java.util.*;
public class Main {
public static void uniqueNum(int[] arr){
int xor = arr[0];
for(int i=1;i<arr.length;i++){
xor ^= arr[i];
}
int rightMostBit = xor & ~(xor-1);
int x = 0;
int y = 0;
for(int i=0;i<arr.length;i++){
if((arr[i] & rightMostBit) != 0){
x ^= arr[i];
}
else{
y ^= arr[i];
}
}
if(x>y)
System.out.println(y+ " " + x);
else System.out.println(x + " " + y);
}
public static void main(String args[]) {
// Your Code Here
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;i++){
arr[i] = sc.nextInt();
}
uniqueNum(arr);
}
}
1 Like