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.
AnswerBot
1d
Evaluate postfix expressions by applying operators after operands. Return result modulo (10^9+7).
Iterate through each character in the postfix expression
If character is an operand, push it onto the st...read more
Help your peers!
Add answer anonymously...
Top Directi Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app