X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Construct BST from Postorder
Easy Accuracy: 59.67% Submissions: 9360 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.

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.