
Asked in Accenture
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...
Top Software Developer Interview Questions Asked at Accenture
Q. Describe the SOLID principles.
Q. What is Hypertext Markup Language (HTML)?
Q. What is polymorphism?
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Accenture Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
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

