Maximize Expression Value
Given an arithmetic expression EXP
containing integer values separated by any of the operators ‘+’, ‘-’, and ‘*’, your task is to place parentheses such that the value of the expression is maximized. Return the maximum value obtained from such parenthetical placement.
Example:
Input:
Expression: '3*5+2'
Output:
21
Explanation:
The maximum value 21
can be achieved by placing the parentheses as 3*(5+2)
.
Constraints:
1 ≤ T ≤ 5
1 ≤ |EXP| ≤ 100
- Time limit: 1 sec
Input:
The first line contains an integer ‘T’ representing the number of test cases. Each of the following T lines contains a string denoting an expression EXP
.
Output:
For each test case, return a single integer indicating the maximum value of the given expression.
Note:
You don’t need to print anything; it has already been taken care of. Implement the function to compute the result.
Be the first one to answer
Add answer anonymously...
Top Paxcom India Software Engineer interview questions & answers
Popular interview questions of Software Engineer
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