


1. The string is made up of lowercase English alphabets, ‘?’ and ‘:’ special characters.
2. The alphabets may be repeated in the string.
3. The expression which uses ‘?:’ is known as ternary expression and the expression will be evaluated as (condition ? value_if_true : value_if_false).
The first line of input contains a single integer 'T', representing the number of test cases.
The first and the only line of each test case contains a string 'STR' representing the ternary expression.
For each test case, return the level order traversal of the resultant binary tree in a space separated elements in a single line . If a node is NULL then # will be considered at its place.
You don’t have to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 100
1<= N <= 10^4
Where ‘N’ is the length of the string.
Time limit: 1 sec
The idea is to use recursion and the tree will be built in a bottom-up approach. As for each node, we need to find its left and right child, but the child will have to find their children first and only then they can be assigned to their parent.
The steps are as follows:
As the associativity of the ternary operator is from right to left, we can build a solution starting from the end of the string.
The steps are as follows: