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.

AnswerBot
4mo
Given an arithmetic expression, place parentheses to maximize the value of the expression.
Identify the operators in the expression ('+', '-', '*').
Consider the precedence of operators to determine whe...read more
Help your peers!
Add answer anonymously...
Paxcom India Software Engineer interview questions & answers
A Software Engineer was asked Q. Determine the Left View of a Binary Tree You are given a binary tree of integers...read more
A Software Engineer was asked Q. Maximize Expression Value Given an arithmetic expression EXP containing integer ...read more
A Software Engineer was asked Q. Sum Tree Conversion Convert a given binary tree into its sum tree. In a sum tree...read more
Popular interview questions of Software Engineer
A Software Engineer was asked Q1. Determine the Left View of a Binary Tree You are given a binary tree of integers...read more
A Software Engineer was asked Q2. Maximize Expression Value Given an arithmetic expression EXP containing integer ...read more
A Software Engineer was asked Q3. Sum Tree Conversion Convert a given binary tree into its sum tree. In a sum tree...read more
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

