Arithmetic Expression Evaluation Problem Statement
You are provided with a string expression
consisting of characters '+', '-', '*', '/', '(', ')' and digits '0' to '9', representing an arithmetic expression in infix notation. Your task is to evaluate this arithmetic expression.
Explanation
In infix notation, operators are placed between their operands.
Note:
1. The '/' operator is considered as floor division.
2. The '*' and '/' operators have higher precedence than '+' and '-'.
3. The string expression always starts with '(' and ends with ')'.
4. It is assured that 'expression' represents a valid infix expression.
5. There will be no division by zero cases.
6. No other characters than the specified ones are present in the string.
7. The operands and final result will fit in a 32-bit integer.
Input
The first line of input contains an integer ‘T’ indicating the number of test cases.
The next T lines each contain a string ‘expression’ representing a test case.
Output
For each test case, output an integer on a new line representing the evaluated value of the arithmetic expression.
Example
Input:
2
((2+3)*(5/2))
((1+2)*(3-1))
Output:
10
6
Constraints
1 ≤ T ≤ 50
3 ≤ |expression| ≤ 104
- Time limit: 1 sec

AnswerBot
3mo
Evaluate arithmetic expressions in infix notation with given operators and precedence rules.
Parse the infix expression to postfix using a stack.
Evaluate the postfix expression using a stack.
Handle ope...read more
Help your peers!
Add answer anonymously...
Facebook Software Developer interview questions & answers
A Software Developer was asked Q. How does Facebook store likes and dislikes?
A Software Developer was asked Q. How does Facebook implement graph search?
A Software Developer was asked Q. How does Facebook Chat work?
Popular interview questions of Software Developer
A Software Developer was asked Q1. How does Facebook store likes and dislikes?
A Software Developer was asked Q2. How does Facebook implement graph search?
A Software Developer was asked Q3. How does Facebook Chat work?
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

