Build Binary Expression Tree From Infix Expression
Infix expression: The expression of the form ‘a operator b’. When an operator is in-between every pair of operands. The expression tree is a binary tree in which each internal node corresponds to the operator and each leaf node corresponds to the operand so for example expression tree for 5 * ( 6 - 3 ) / 2 - 8 would be:
The first line of input contains an integer 'T' representing the number of test cases. The first line of each test case contains a string S representing infix expression.
For each test case, return the binary expression tree, whose inorder traversal is the same as 'S'. Return -1 instead of NULL. The output for each test case is printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5 1 <= N <= 5000 Operands are only numbers between 0 and 9 (included). It is guaranteed that ‘S’ is a valid infix expression. Time limit: 1 sec
Ninja and Numbers
Longest Palindromic Substring
Next Greater Element II