Different Ways to Add Parentheses
A medium-tier problem at 72% community acceptance, tagged with Math, String, Dynamic Programming. Reported in interviews at DeltaX and 2 others.
Different Ways to Add Parentheses is a medium-difficulty problem that asks you to compute all possible results from different ways of inserting parentheses into a numeric expression. DeltaX, Salesforce, and Flipkart have all reported asking it. The trap is that most candidates try to brute-force all permutations of parentheses placements, which balloons the search space fast. The actual solution uses divide-and-conquer with memoization, splitting the expression at each operator and recursively computing all left and right sub-results. If this pattern hits your live assessment and you freeze on the recursion structure, StealthCoder surfaces a working solution in seconds, invisible to the proctor.
Companies that ask "Different Ways to Add Parentheses"
Different Ways to Add Parentheses is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.
Get StealthCoderThe key insight is that you don't generate parentheses strings. Instead, you recursively split the expression at each operator, compute all possible results from the left substring, compute all from the right substring, then combine them using the operator at that split point. For example, '1+2*3' splits at '+' into '1' and '2*3', and at '*' into '1+2' and '3'. Each split spawns new recursive calls, and memoization caches results for identical substrings so you don't recompute. Common pitfall: parsing the expression wrongly or forgetting that a single number is a base case that returns a list containing just that number. Another trap is not memoizing aggressively enough. The recursion tree explodes without it. If the operator chain is long and you hit this in the live OA without the pattern locked in, StealthCoder is your hedge.
Pattern tags
You know the problem.
Make sure you actually pass it.
Different Ways to Add Parentheses recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Different Ways to Add Parentheses interview FAQ
Is this actually asked at big companies?+
Yes. DeltaX, Salesforce, and Flipkart all report it. It's a medium-difficulty problem with a 72% acceptance rate, so it's not rare, but the recursion plus memoization combo trips up candidates who haven't seen the pattern before.
What's the trick I'm missing if I try brute force?+
Brute force generates all permutations of parenthesis placements, which is exponential and inefficient. The trick is to split at each operator recursively, compute all results for left and right halves separately, then combine them. Memoization prevents recomputation of overlapping subproblems.
How does this relate to Dynamic Programming?+
It's a textbook divide-and-conquer with memoization, which is bottom-up DP. You solve subproblems (substrings of the expression), cache results, and reuse them. This avoids the exponential blowup of naive recursion and is the core DP pattern for expression evaluation problems.
What's the hardest part to get right?+
Parsing the operator position correctly and ensuring your recursion base case handles single numbers. Many candidates also forget to memoize, which tanks performance. If you're splitting and storing results per substring, you must cache before returning.
Does the input have spaces or weird formats?+
The input JSON doesn't specify. Assume the expression is a string of digits and operators with no spaces. In the live OA, check the problem statement. The algorithm stays the same regardless.
Want the actual problem statement? View "Different Ways to Add Parentheses" on LeetCode →