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
4mo
Evaluate arithmetic expressions in infix notation with given operators and precedence rules.
Parse the infix expression to postfix using a stack and then evaluate the postfix expression using another s...read more
Help your peers!
Add answer anonymously...
SquadStack Product Engineer interview questions & answers
A Product Engineer was asked Q. Reverse Words in a String: Problem Statement You are given a string of length N....read more
A Product Engineer was asked Q. What is an Inner Join?
A Product Engineer was asked Q. How would you design a parking lot system?
Popular interview questions of Product Engineer
A Product Engineer was asked Q1. Reverse Words in a String: Problem Statement You are given a string of length N....read more
A Product Engineer was asked Q2. What is an Inner Join?
A Product Engineer was asked Q3. How would you design a parking lot system?
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

