my logic is correct but is giving the wrong output
Why my question is giving the wrong output
There are two things in the question that you are missing:-
(i) As the array is given and you are not defined that which traversal is this, so what here you will do is you will take first element as the root and next elements are inserted according to their position.
For eg:- array is 10 5 13 so here root will be 10 , root.left = 5 and root.right = 13
(ii) In second line you are asked to print the numbers between k1 and k2 range and they must be in sorted order.
One more thing, take care of the format of output(exactly same as given in output) and new line after each print statement.
Feel free to ask if you have any furthur queries in this question or if you want help for writing code.
Please mark it as resolved to acknowledge me that you get it.
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.