Please help me where i am getting wrong answer in problem KTH ROOT problem

import java.util.*;

public class Main{

public static void main(String args[]){

    Scanner sc = new Scanner(System.in);

    int t = sc.nextInt();

    int n = sc.nextInt();

    int k = sc.nextInt();
    int arr [] = new int [ k- n];
    for(int i = k ; i< n ; i++){
        arr[i] = sc.nextInt();
    }
    kthRoot( arr, n, k);
}

public static void kthRoot( int arr[] , int n, int k){
    int left = k ;
    int right = n ;
    int ans ;
    int mid ;
    while (left < right){
         mid = (left + right)/2 ;
        int d = mid ^ left;
        if( d <= n){
            mid = mid + 1 ;
            left = mid ;
            right = n ;
            ans = mid;
        }
        else if(d >= n){
            mid = mid - 1 ;
            ans = mid ;
            left = k;
            right = mid ;
            
        }
        else
         ans = mid ;
	 
    
    System.out.println(ans);
	}
    
}

}

@abhisheksinghchauhan442
^ (bitwise XOR)
Binary XOR Operator copies the bit if it is set in one operand but not both.
you need to take the power not xor of mid & k. and use long datatype to store value of n as it value can go up to 10^15 and its better if your store other value in long as well.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.