Geeksforgeeks

Error

Given a string that contains ternary expressions. The expressions may be nested. You need to convert the given ternary expression to a binary Tree and return the root.

**Example 1:**** **

Input:a?b:cOutput:a b cExplanation:string expression = a?b:c So the binary tree for the above expression is: a / \ b c

**Example 2:**

Input:a?b?c:d:eOutput:a b c d eExplanation:string expression = a?b?c:d:e So the binary tree for the above expression is:a / \ b e / \ c d

**Your Task:**

This is a function problem, you don't need to read input/output. Just complete the function **convertExpression() **that take** string and index(initialized from 0) **as parameters and returns the root node of the binary tree

**Constraints:**

1 <= T <= 100

1 <= |String| <= 100

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Convert Ternary Expression to Binary Tree

...