This is my code my preorder output 42165 and test case output 42156

import java.util.*;
public class Main {
private class Node{
Node left;
Node right;
int data;
}
private Node root;
public void constract(int ar[]){
Arrays.sort(ar);
this.root=constract(ar,0,ar.length);
}
private Node constract(int ar[],int low,int high) {
if(low>=high)
{
return null;
}
int mid=(low + high)/2;
Node nn=new Node();
nn.data=ar[mid];
nn.left=constract(ar,low,mid);
nn.right=constract(ar,mid+1,high);
return nn;
}
void preOrder() {
preOrder(this.root,0);
}
public void preOrder(Node node,int temp) {
if(node==null)
return;
if(!(temp==0)) {
System.out.print(" ");

		}
		temp++;
		System.out.print(node.data);
		preOrder(node.left,temp);
		preOrder(node.right,temp);
	}
   static Scanner scn=new Scanner(System.in);
   public static void main(String[] args) {
	   Main BST=new Main();
	   int t=scn.nextInt();
	   while(t!=0) {
		   int n=scn.nextInt();
		   int ar[]=new int[n];
		   for(int i=0;i<n;i++) {
			   ar[i]=scn.nextInt();
		   }
		   int s=scn.nextInt();
		   int end=scn.nextInt();
		   BST.constract(ar);
		   System.out.print("# Preorder : ");
		   BST.preOrder();
		   System.out.println();
			System.out.print("# Nodes within range are : ");
			BST
			.printGivenRange(s,end);
		   t--;
	   }
	   
   }
	public  void printGivenRange(int n,int m) {
		printGivenRange(n,m,this.root);
	}
	private  void printGivenRange(int n, int m,Node node) {
		if(node==null) {
			return;
		}
if(node.data>=n && node.data<=m) {
	System.out.print(node.data+" ");
}
printGivenRange(n,m,node.left);
printGivenRange(n,m,node.right);
	}

}

@sksumitkumardiwaker,
https://ide.codingblocks.com/s/231462 corrected code.

There was an error in the construction method and in range method.

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.