Infix to Postfix Conversion

Convert a given infix expression, represented as a string EXP, into its equivalent postfix expression.

Explanation:

An infix expression is formatted as a op b where the operator is placed between operands. A postfix expression is formatted as a b op where the operator follows the operands.

For more details on infix and postfix expressions, refer to these links: Infix Notation and Postfix Notation.

Input:

The first line of input contains an integer 'T' denoting the number of test cases to run. Each test case consists of a single line containing a string 'EXP', which is a valid infix expression.

Output:

For each test case, print the corresponding postfix expression of the given infix expression. Each result should be printed on a new line.

Example:

Input:
EXP = '3+4*8'
Output:
3 4 8 * +
Explanation:

In the given example, multiplication is performed before addition, resulting in the postfix expression 3 4 8 * +.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 5000, where 'N' is the length of 'EXP'
  • The expression can contain digits, lowercase English letters, and the characters ‘(’, ‘)’, ‘+’, ‘-’, ‘*’, ‘/’, ‘^’.
  • Time Limit: 1 sec
Note:
You are not required to print anything; the function implementation will handle the output.
AnswerBot
4mo

Convert infix expression to postfix expression by following operator precedence rules.

  • Use a stack to keep track of operators and operands while converting infix to postfix.

  • Follow the precedence rules ...read more

Help your peers!
Select
Add answer anonymously...

Oracle Financial Services Software Associate Consultant interview questions & answers

An Associate Consultant was asked 3mo agoQ. Write a function to reverse a string in Java.
An Associate Consultant was asked 8mo agoQ. How can you swap two numbers without using a temporary variable?
An Associate Consultant was asked 9mo agoQ. Explain the concepts of OOPs.

Popular interview questions of Associate Consultant

An Associate Consultant was asked 3mo agoQ1. Write a function to reverse a string in Java.
An Associate Consultant was asked 8mo agoQ2. How can you swap two numbers without using a temporary variable?
An Associate Consultant was asked 8mo agoQ3. Write pseudocode to determine if a string is a palindrome.
Oracle Financial Services Software Associate Consultant 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