We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I cannot get test cases 17, 19, 23
Test case 17: Expected = 262143 Actual = 262141
Test case 19: Expected = 65535 Actual = 65534
Test case 23: Expected = 262141 Actual = 262140
Here is my code, any input is appreciated:
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner in = new Scanner(System.in);
int count = in.nextInt();
int arr[] = new int[count];
Stack<Integer> stack = new Stack<Integer>();
int currS1 = 0;
int maxS1 = 0;
arr[0] = in.nextInt();
stack.push(0);
for (int i = 1; i < count; i++)
{
arr[i] = in.nextInt();
currS1 = arr[i] ^ arr[i - 1];
maxS1 = Math.max(currS1, maxS1);
while (!stack.empty() && arr[stack.peek()] > arr[i])
{
int top = stack.pop();
if (i != top + 1)
{
currS1 = arr[top] ^ arr[i];
maxS1 = Math.max(currS1, maxS1);
}
}
stack.push(i);
}
while(!stack.empty())
{
int top = stack.pop();
if (stack.empty())
{
break;
}
int peek = stack.peek();
currS1 = arr[top] ^ arr[peek];
maxS1 = Math.max(currS1, maxS1);
}
System.out.println(maxS1);
}
AND xor OR
You are viewing a single comment's thread. Return to all comments →
I cannot get test cases 17, 19, 23 Test case 17: Expected = 262143 Actual = 262141 Test case 19: Expected = 65535 Actual = 65534 Test case 23: Expected = 262141 Actual = 262140
Here is my code, any input is appreciated: