Postfix Expression Evaluation Problem Statement

Given a postfix expression, your task is to evaluate the expression. The operator will appear in the expression after the operands. The output for each expression should be the result modulo (109+7). Use modular division when necessary.

Example:

Explanation:
Infix expression: A + B * C - D
Postfix expression: A B + C D - *

Input:

The first line contains an integer ‘T’ representing the number of test cases.
Each of the next ‘T’ lines contains one postfix expression.

Output:

For each test case, print the integer result of evaluating the given postfix expression.

Constraints:

  • The first line of input contains an integer ‘T’ such that 1 ≤ T ≤ 100
  • Each postfix expression has a length ‘N’ such that 1 ≤ N ≤ 103
  • The operands in the expression are represented by integers ‘NUM’ such that 1 ≤ NUM ≤ 100
  • Operators include: '*', '/', '+', '-'
  • Operators and operands are separated by a space
  • No brackets are present in the postfix expression

Note:

You do not need to print the expected output; just implement the function.
Be the first one to answer
Add answer anonymously...
Accenture Application Development Associate Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter