567. Convert Infix to Postfix

EasyStackStackString

Given a valid infix expression string s with single-character operands (letters or digits), the binary operators + - * / ^ (with ^ right-associative and standard precedence ^ > * / > + -), and parentheses, convert it to its postfix (Reverse Polish) form and return it as a string with no separators. The input is JSON {s}.

Input: JSON {s}.

Output: String — the postfix expression.

Examples

Example 1
Input: {"s":"a+b*c"}
Output: abc*+
Explanation: Multiplication binds tighter than addition.
Example 2
Input: {"s":"(a+b)*c"}
Output: ab+c*
Explanation: Parentheses force the addition first.
Example 3
Input: {"s":"a^b^c"}
Output: abc^^
Explanation: Exponent is right-associative.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →