← DiffPush

Postfix to Infix Conversion

Standard Bar Stack and Queues · Infix, Postfix, and Prefix O(n) · O(n)

The Robotic Arm Script Rewriter

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.

Constraints

Examples

Example 1

Input: {"expression":"ab*c+"}
Output: "((a*b)+c)"
The * joins a and b first; the + then wraps that whole group with c.

Example 2

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.

Solve this in your browser →

Also on LeetCode ↗