Back to problems

Serialize Arithmetic Expression Tree with Minimum Parentheses

Algorithm · Waymo · Hard

Requirements The input is a binary expression tree. Leaves contain variables, while every internal node contains exactly two children and one of +, -, *, or /. Produce an infix string that reconstructs the identical tree when parsed using ordinary operator precedence and left-associative evaluation. Parentheses must be used sparingly: include them only when precedence or associativity makes them necessary. Notes * and / have higher precedence than + and -. The operators -…

Checking your access…