You are given an infix expression as a string s and need to convert it into a postfix expression.
Note: Follow the operator precedence:
Example 1
Input: s = "x+y*z"
Output: xyz*+
Explanation: * has higher precedence than +, so y*z is evaluated first. The postfix expression becomes xyz*+.
Example 2
Input: s = "a*b+c/d"
Output: ab*cd/+
Explanation: * and / have the same precedence, so a*b and c/d are evaluated first, followed by +. The postfix expression is ab*cd/+.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
x+y*z
xyz*+
a*b+c/d
ab*cd/+