It gives the correct output but it gets failed to pass all the test cases

package Array;

import java.util.Scanner;

public class lowerAndUpperBound {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner s = new Scanner(System.in);
	int n = s.nextInt();
	int[] arr = new int[n];
	///////////////////////-->
	for(int i=0; i<n; i++) {
		arr[i] = s.nextInt();
	}
	///////////////////////--<
	
	int q = s.nextInt();
	int[] qry = new int[q];
	///////////////////////
	for(int i=0; i<q; i++) {
		qry[i] = s.nextInt();
	}
	///////////////////////
	int[] lb = new int[q];
	int[] ub = new int[q];
	for(int i=0; i<q; i++) {
		lb[i] = lowerBound(arr, qry[i]);
		ub[i] = upperBound(arr, qry[i]);
	}
	
	///// Print
	for(int i=0; i<q; i++) {
		System.out.println(lb[i] + " " + ub[i]);
	}
	s.close();
}

private static int upperBound(int[] arr, int k) {
	// TODO Auto-generated method stub
	int lo = 0, hi = arr.length -1;
	while(hi - lo > 1) {
		int mid = lo + (hi-lo)/2;
		if(arr[mid] <= k) {
			lo = mid + 1;
		}else {
			hi = mid;
		}
	}
	if(arr[lo] > k) {
		return lo;
	}
	if(arr[hi] > k) {
		return hi;
	}
	return -1;
}

private static int lowerBound(int[] arr, int k) {
	// TODO Auto-generated method stub
	int lo = 0, hi = arr.length -1;
	while(hi - lo > 1) {
		int mid = lo + (hi-lo)/2;
		if(arr[mid] < k) {
			lo = mid + 1;
		}else {
			hi = mid;
		}
	}
	if(arr[lo] >= k) {
		return lo+1;
	}
	if(arr[hi] >= k) {
		return hi+1;
	}
	return -1;
}

}