Skip to main content

Prefix to Postfix Conversion

easy
Software engineer

Given a string prefix expression, convert it to the corresponding postfix expression.

  • A prefix expression is one where the operator precedes its operands (e.g., *+AB-CD).
  • A postfix expression is one where the operator follows its operands (e.g., AB+CD-*).

Assume the input string contains only single-digit numbers, single uppercase letters (A-Z), and the operators +, -, *, and /. The input will always be a valid prefix expression.

Example 1

Input

prefix = "+12"

Output

"12+"

Explanation

The prefix expression `+12` represents the infix operation `1 + 2`. In postfix notation, the operator follows the operands, resulting in `12+`.

Example 2

Input

prefix = "-*345"

Output

"34*5-"

Example 3

Input

prefix = "*+AB-CD"

Output

"AB+CD-*"

Constraints

  • 1 <= prefix.length <= 100
  • The expression contains only single-digit numbers, uppercase letters, and operators +, -, *, /.

OA

RecursionSimulationStackString
Language
Code editor loads in the browser.

Output

Input

"+12"

Expected

"12+"

Your output

Run to see your output.