https://ide.codingblocks.com/s/62182
why my code is giving wrong answer
Error in code (BST Keys)
Hey anshu… your built tree function is wrong, you are given pre order, now copy them in another array and sort it, you’ll get inorder traversal. then you have to build tree using preorder and inorder traversal.
you mean i have to build tree from preorder(given) and inorder(after sorting) and theni have to print preorder traversal
ihave done that now its showing runtime error
though its working fine on sample input
Hi Anshu, the array given in the input is not the preorder traversal of the BST to be formed. It is just a random unsorted array and you need to create a BST from the given unsorted array. I am sharing the build tree function with you for your reference.
You can refer to the code here:
https://ide.codingblocks.com/s/62474
Now, you can apply you logic to find keys in given range.
@Anshu-Rai-1394292720706575 hi anshu your output was not matching with sample one i have corrected your code this.