what is the problem with my code anyone please help…
Range Xor problem
hey @Mukul70
Code is fine :
just a changes int currXor = a.get(i) ^ x; instead of int currXor = a.get(i) ^ 6;
correct code :
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
List a = new ArrayList<>();
int q = sc.nextInt();
while (q-- > 0) {
int type = sc.nextInt();
if (type == 0) {
int x = sc.nextInt();
a.add(x);
}
if (type == 1) {
int L = sc.nextInt();
int R = sc.nextInt();
int x = sc.nextInt();
int num = -1;
int max = Integer.MIN_VALUE;
for (int i = L - 1; i < R; i++) {
int currXor = a.get(i) ^ x;
if (currXor > max) {
max = currXor;
num = a.get(i);
}
}
System.out.println(num);
}
}
}
}
Silly mistake anyway thanks brother…
Actually I was thinking there is another solution of the problem and my code is not running for all test cases
Thanks a lot…
hello brother,
this is my boubt please help