Doubt in Build BST Question

In the question BuildBST (https://online.codingblocks.com/player/12512/content/5297), for the input order of the input in the test case (1 2 3 4 5 6 7) , the output should be a skewed bst where 1 is the root node.
However, the output is shown as 4 2 1 3 6 5 7 where 4 is the root node.

How are we supposed to consider the input?

My Code https://ide.codingblocks.com/s/51560

Hey Sanskar, it is mentioned in the problem that you have to form a balanced Binary Search Tree and then print preorder traversal of the tree. So, when you form a balanced binary tree of input => (1 2 3 4 5 6 7) then its pre-order traversal will be => 4 2 1 3 6 5 7

1 Like