Construct BST from Postorder
Easy Accuracy: 62.12% Submissions: 8026 Points: 2

Given postorder traversal of a Binary Search Tree, you need to construct a BST from postorder traversal. The output will be inorder traversal of the constructed BST.

 

Example 1:

Input:
6
1 7 5 50 40 10

Output:
1 5 7 10 40 50

Explanation:
Testcase 1: The BST for the given post order traversal is:


Thus the inorder traversal of BST is: 1 5 7 10 40 50.

 

Your Task:
The task is to complete the function constructTree() which takes an array post[], size as as the argument and returns the root of BST.

 

Expected Time Complexity: O(Height of the BST)
Expected Auxiliary Space: O(Height of the BST)

 

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

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Construct BST from Postorder

Output Window