Medium · Stacks & Queues

Infix to postfix

Given a string exp holding a valid infix expression of single-digit operands and the operators +, -, * and / (no parentheses; spaces may appear), return its postfix form without spaces, where * and / bind tighter than + and - and operators of equal precedence group left to right.

Examples

Example 1

{
  "exp": "2+3*4"
}

Output: 234*+

Example 2

{
  "exp": "4*2+3-1"
}

Output: 42*3+1-

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Stacks & Queues problems