Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

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 10Output:1 5 7 10 40 50Explanation: 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.

Click here to view old Disqus comments.

Login to report an issue on this page.

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

YesLoading...

Construct BST from Postorder

...