Standard Bar Stack and Queues · Infix, Postfix, and Prefix O(n) · O(n)
Warehouse robots execute action scripts in operator-last order (`A B *` means apply the join action to A then B), but safety auditors review scripts in ordinary infix notation. The rewriter scans the script left-to-right; each operator grabs the two most recent script fragments from a clipboard and wraps them with the operator in between.
Input: A string expression in valid postfix form with single alphanumeric operands.
Output: Return the fully parenthesized infix expression as a string.
1 <= expression.length <= 10^5Operands are single letters or digitsThe expression is guaranteed to be a valid postfix expressionInput: {"expression":"ab*c+"}
Output: "((a*b)+c)"
The * joins a and b first; the + then wraps that whole group with c.
Input: {"expression":"ABC/-AK/L-*"}
Output: "((A-(B/C))*((A/K)-L))"
Forward scanning rebuilds the exact infix tree the prefix conversion produced in reverse.