Print BST keys in the given range its showing test cased failed idk ehy i tried for almost all possible test cases

here is the link of the code

hi shivam
consider your code for the following test cases
6
10
21 18 2 6 14 24 12 13 3 4
5 10
10
14 17 7 18 12 5 4 6 21 24
11 17
10
16 11 15 20 2 22 4 25 17 10
16 25
10
12 18 9 23 15 13 25 11 22 16
7 15
10
15 7 3 17 12 6 8 16 19 2
12 20
7
2 3 4 5 6 7 8
4 9
expected output:

Preorder : 21 18 2 6 3 4 14 12 13 24

Nodes within range are : 6

Preorder : 14 7 5 4 6 12 17 18 21 24

Nodes within range are : 12 14 17

Preorder : 16 11 2 4 10 15 20 17 22 25

Nodes within range are : 16 17 20 22 25

Preorder : 12 9 11 18 15 13 16 23 22 25

Nodes within range are : 9 11 12 13 15

Preorder : 15 7 3 2 6 12 8 17 16 19

Nodes within range are : 12 15 16 17 19

Preorder : 2 3 4 5 6 7 8

Nodes within range are : 4 5 6 7 8

your output:

Preorder : 12 3 2 4 6 18 13 14 21 24

Nodes within range are : 6

Preorder : 12 5 4 6 7 18 14 17 21 24

Nodes within range are : 12 14 17

Preorder : 15 4 2 10 11 20 16 17 22 25

Nodes within range are : 16 17 20 22 25

Preorder : 15 11 9 12 13 22 16 18 23 25

Nodes within range are : 9 11 12 13 15

Preorder : 8 3 2 6 7 16 12 15 17 19

Nodes within range are : 12 15 16 17 19

Preorder : 5 3 2 4 7 6 8

Nodes within range are : 4 5 6 7 8

i dont understand why my preorder is coming different i am sorting the array and then forming the bst

dont sort the array.
without that form the bst.

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.