To print range of entries in BST

Please point out error in code.
TLE is coming.

@vidit.103
input
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

ans
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
check for it

please provide code.
I am unable to spot error in my code.
Kindly rectify the code.

@vidit.103


compare your code with this corrected one

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.