MEDIUMasked at 2 companies

Minimize Result by Adding Parentheses to Expression

A medium-tier problem at 68% community acceptance, tagged with String, Enumeration. Reported in interviews at Pinterest and 1 others.

Founder's read

You're given a string that looks like a math expression with two numbers and a minus or plus operator. The trick is to throw parentheses around any substring and evaluate that first, then do the rest of the calculation. Pinterest and Snap have asked this. It's a STRING problem dressed up as math. The intent is to force you to enumerate all possible parenthesis placements and find which one gives the smallest result. Most candidates overthink it or miss that you can't just wrap random parts. You need to be systematic.

Companies asking
2
Difficulty
MEDIUM
Acceptance
68%

Companies that ask "Minimize Result by Adding Parentheses to Expression"

If this hits your live OA

Minimize Result by Adding Parentheses to Expression 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. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The expression is fixed: `num1 operator num2`. You can place parentheses around any contiguous substring and it changes the evaluation order. The key insight is that parentheses force that substring to be evaluated as a single number first. If you wrap part of num1 or part of num2 or split across the operator, you get different results. Enumeration means you try every valid placement, compute the result, track the minimum. The pitfall: candidates try to optimize or apply algebra rules instead of just brute-forcing every substring. The expression is small, so brute force wins. If you freeze on the pattern in your live OA, StealthCoder runs invisibly and surfaces the full enumeration and calculation. String parsing and integer arithmetic are the only skills you need.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Minimize Result by Adding Parentheses to Expression 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. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimize Result by Adding Parentheses to Expression interview FAQ

Is this really just enumerate all substrings and evaluate?+

Yes. Every valid placement of parentheses changes how the expression evaluates. You generate every substring position, wrap it in parens, evaluate left-to-right with that grouping, and track the minimum. It's brute force by design. The expression is always small enough that this runs instantly.

Why do Pinterest and Snap ask this?+

It tests your ability to enumerate systematically and implement correct expression evaluation. You need to handle substring extraction, type conversion, and arithmetic carefully. It's not hard algorithmically, but careless parsing or off-by-one errors kill it. They're checking attention to detail.

What's the gotcha with parentheses placement?+

Not every substring is a valid placement. You can't wrap the operator alone. You need at least one digit on each side of the operator after parentheses are applied. Some placements create intermediate negative numbers, which is fine. The trick is enumerating valid positions correctly without skipping or double-counting.

How does this relate to String and Enumeration topics?+

String: you're parsing the expression, extracting substrings, handling operator detection. Enumeration: you're trying all valid parenthesis placements, not using a clever formula. Together they test methodical problem-solving, not algorithmic wizardry. Acceptance rate is 67.5%, so most people solve it with clean enumeration.

Can I optimize this or is brute force the only way?+

Brute force is the intended solution and the only reasonable one. The expression is always small (two numbers, one operator). There's no mathematical trick to skip placements. Trying to optimize will waste time in an interview. Enumerate, evaluate, return the minimum.

Want the actual problem statement? View "Minimize Result by Adding Parentheses to Expression" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.