Print bst in given range


not passing all test cases

hello @pradyumn25jain
ur code is correct,may be ur build tree function is constructing bst of different structure.
so once try to build normal bst by inserting each element one by one and then submit

amm the structure also seems correct

once try . . . . . .

yeah i did on the test case provided and i am getting the right answer . maybe give me a testcase on which my code wont work…

try ur code for following test case->

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

correct 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

alright will check thanks

21 18 2 6 14 24 12 13 3 4 please see the test case is wrong

why ?

i think it is correct

try forming a bst using the min max method … numbers smaller then 21 should have been on the left of 24

build normal bst by inserting elements one by one

yeah the input is not given in preorder