885. Requirements needed to construct a unique BT

Given a pair of tree traversal, return true if a unique binary tree can be constructed otherwise false. Each traversal is represented with integer: 1 -> Preorder , 2 -> Inorder , 3 -> Postorder.

Example 1:

Input : 1 2

Output : true 

Explanation : Answer is True.

It is possible to construct a unique binary tree. This is because the preorder traversal provides the root of the tree, and the inorder traversal helps determine the left and right subtrees.

Example 2:

Input : 2 2

Output : false

Explanation : Two inorder traversals are insufficient to uniquely determine a binary tree.

Now Your Turn!

Pick the correct output for the given input

Input : 1 3

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= a, b <= 3

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution{
public:
bool uniqueBinaryTree(int a, int b){
//your code goes here
}
};
Test Case

Input:

A
B