BETA
Convert Level Order Traversal to BST
Submissions: 638   Accuracy:

58.15%

  Difficulty: Medium
         

Given a level order traversal of a BST, your task is to complete the function constructBst(),that construct the BST (Binary Search Tree) from its given level order traversal.

Examples:

Input : arr[] = {7, 4, 12, 3, 6, 8, 1, 5, 10}
Output : BST: 
        7        
       / \       
      4   12      
     / \  /     
    3  6 8    
   /  /   \
  1   5   10

Input:
The functio constructBst() takes two argument as input, an array (arr) the contains the level order traversal of the BST and an integer N denoting the size of the array.
There will be T test cases and for each test case the function will be called separately.

Output:
For each test return the pointer to the root of the newly constructed BST.

Constraints:
1<=T<=100
1<=N<=103

Example:
Input:

2
9
7 4 12 3 6 8 1 5 10
6
1 3 4 6 7 8
Output:
1 3 4 5 6 7 8 10 12 
1 3 4 6 7 8 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: harshitsidhwa


Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.