Medium Accuracy: 50.68%
Submissions: 13461 Points: 4
Construct a binary tree of size N using two given arrays pre and preLN. Array pre represents preorder traversal of a binary tree. Array preLN has only two possible values ‘L’ and ‘N’. The value ‘L’ in preLN indicates that the corresponding node in Binary Tree is a leaf node and value ‘N’ indicates that the corresponding node is a non-leaf node. Note: Every node in the binary tree has either 0 or 2 children.
You dont need to read input or print anything. Complete the function constructTree() which takes N, pre and preLN as input parameters and returns the root node of the constructed binary tree. Note: The output generated by the compiler will contain the inorder traversal of the created binary tree.
Expected Time Complexity: O(N) Expected Auxiliary Space: O(N)