can u some hint. I am think like that if root node has both the elements then print the root. but its wrong if take the leaf nodes when the level>2 .
Print BST keys in given range
hello @Vikaspal
this is simple problem based on tree traversal.
do a preorder traversal of the given tree.
if value of current node is in between k1 and k2
then push it in a vector or arr .
after traversal is done. print ur vector.
@aman212yadav can we do like, inorder traversal first go the left part and then dataa check root is between k1 and k2 and then print the node and then right part no used of vectors.
which solution is efficient.
@aman212yadav when in question we have the arrays as inputs does it count in space while calculating complexity
no we dont count that space in our space complexity.
actually we have to print two things in this problem.
a) do preorder traversal and print the node.
b) after that do inorder and print the nodes in given range
just add cout<<"\n";
after calling printtree function ,it will work.
ur updated code->
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.