Infix to Postfix Conversion

You are provided with a string EXP which represents a valid infix expression. Your task is to convert this given infix expression into a postfix expression.

Explanation:

An infix expression is of the form a op b where the operator is placed between the operands. Conversely, a postfix expression is of the form a b op where the operator is placed after the operands.

Input:

The first line of input contains an integer ‘T’ representing the number of test cases. Each test case contains one string ‘EXP’, a valid infix expression.

Output:

For each test case, output the corresponding postfix expression on a new line.

Example:

Input:
EXP = ‘3+4*8’
Output:
3 4 8 * +

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 5000 where N is the length of EXP
  • The expression contains digits, lowercase English letters, parentheses (), and operators +, -, *, /, ^
  • Time Limit: 1 sec

Note:

You are not required to print anything. Implement the function as specified.

AnswerBot
4mo

Convert a given infix expression to postfix expression.

  • Use a stack to keep track of operators and operands.

  • Follow the rules of precedence for operators (*, / have higher precedence than +, -).

  • Handle p...read more

Help your peers!
Select
Add answer anonymously...

Delhivery Associate Software Engineer interview questions & answers

An Associate Software Engineer was asked Q. Infix to Postfix Conversion You are provided with a string EXP which represents ...read more
An Associate Software Engineer was asked Q. Maximum Sum Path in a Binary Tree Problem Statement You are provided with a bina...read more
An Associate Software Engineer was asked Q. Find First Repeated Character in a String Given a string 'STR' composed of lower...read more

Popular interview questions of Associate Software Engineer

An Associate Software Engineer was asked Q1. Infix to Postfix Conversion You are provided with a string EXP which represents ...read more
An Associate Software Engineer was asked Q2. Maximum Sum Path in a Binary Tree Problem Statement You are provided with a bina...read more
An Associate Software Engineer was asked Q3. Find First Repeated Character in a String Given a string 'STR' composed of lower...read more
Delhivery Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits