Standard Bar Stack and Queues · Infix, Postfix, and Prefix O(n) · O(n)
Legacy diagnostics devices broadcast commands operator-last, while the modern control bus expects operator-first messages. The gateway scans each incoming command left-to-right, holding partially translated messages on a buffer; on every operator it re-emits the operator first, followed by the two buffered messages in swapped order.
Input: A string expression in valid postfix form with single alphanumeric operands.
Output: Return the equivalent prefix (Polish) expression as a string.
1 <= expression.length <= 10^5Operands are single letters or digitsThe expression is guaranteed to be a valid postfix expressionInput: {"expression":"ABC/-AK/L-*"}
Output: "*-A/BC-/AKL"
Each operator is hoisted to the front of the two fragments it merges, inverting the postfix layout.
Input: {"expression":"ab+c*"}
Output: "*+abc"
The + merges a and b first; the * then fronts the whole group with c.