InterviewBit Academy is now Scaler!
InterviewBit Academy is now Scaler Academy!

Infix to Postfix

Given string A denoting an infix expression. Convert the infix expression into postfix expression.

String A consists of ^, /, *, +, -, (, ) and lowercase english alphabets.

where lowercase english alphabets are operands and ^, /, *, +, - are operators.

Find and return the postfix expression of A.


  1. ^ has highest precedence.
  2. / and *** have equal precedence but greater than **+ and -.
  3. + and - have equal precedence and lowest precedence among given operators.

Input Format

The only argument given is string A.

Output Format

Return the postfix conversion of A.


1 <= length of the string <= 500000
-10^9 <= A[i] <= 10^9 

For Example

Input 1:
    A = "x^y/(a*z)+b"
Output 1:

Input 2:
    A = "a+b*(c^d-e)^(f+g*h)-i"
Output 2:
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Infix to Postfix on Interview Code Editor
  • Hints are not available for this problem


Click here to start solving coding interview questions