Tets case failled

what is wrong with my code
"
import java.util.*;
public class Main {
public class Node {
int data;
Node left;
Node right;
}

private Node root;

public Main(int arr[]) {
	this.root = construct(arr, 0, arr.length - 1);
}

private Node construct(int[] arr, int i, int j) {
	// TODO Auto-generated method stub
	if (j < i) {
		return null;
	}
	int mid = (i + j) / 2;
	Node nn = new Node();
	nn.data = arr[mid];
	nn.left = construct(arr, i, mid - 1);
	nn.right = construct(arr, mid + 1, j);
	return nn;
}
public static void main(String args[]) {
	Scanner scn=new Scanner(System.in);
	int t=scn.nextInt();
	while(t>0){
        int n=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++){
			arr[i]=scn.nextInt();
		}
		Arrays.sort(arr);
		Main m=new Main(arr);
		int k1=scn.nextInt();
		int k2=scn.nextInt();
		System.out.print("# Preorder : ");
		m.preorder();
		System.out.println();
        m.printInRange(k1,k2);
		t--;
	}

}

public void printInRange(int lo, int hi) {
	ArrayList<Integer> list=new ArrayList<>();
	printInRange(root, lo, hi,list);
	System.out.print("# Nodes within range are : ");
	for(int i=0;i<list.size();i++){
		System.out.print(list.get(i)+" ");
	}
	System.out.println();
}

private void printInRange(Node node, int lo, int hi,ArrayList<Integer> list) {

	if (node == null) {
		return;
	}

	if (node.data < lo) {
		printInRange(node.right, lo, hi,list);
	} else if (node.data > hi) {
		printInRange(node.left, lo, hi,list);
	} else {

		printInRange(node.left, lo, hi,list);
		list.add(node.data);
		printInRange(node.right, lo, hi,list);
	}

}
public void preorder(){
	preorder(this.root);
}
public void preorder(Node root){
	if(root==null){
		return ;
	}
	System.out.print(root.data+" ");
	preorder(root.left);
	preorder(root.right);
}

}
"

@guptadev354,

https://ide.codingblocks.com/s/220023 Here is the correct code.

  1. Instead of using a arraylist to get your answer, simply print them instead of adding to arraylist.
  2. Don’t sort the array before construction.
  3. You need to update root node as well, while constructing the tree.