Minimize Expression Value with Parentheses (for mle also :)
Reported by candidates from ByteDance's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The ByteDance OA reported in August 2026 hands you a string like 247+38 and a stated budget of O(n^4), which tells you brute force is the intended answer. If you're taking it in the next day or two, relax. It's the classic minimize-expression-with-parentheses setup: try every left and right parenthesis position, evaluate, keep the smallest. The trap isn't the algorithm, it's the edge cases around empty factors and the plus sign. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but this one is very doable on your own.
The problem
You are given a string expr representing the sum of two positive integers. Neither integer contains a zero in its decimal representation. Insert exactly one pair of parentheses so that the plus sign is inside the parentheses and there is at least one digit between the plus sign and each parenthesis. Any digits outside the parentheses form multiplication factors. If there are no digits on one side of the parentheses, the missing factor is 1. For example, 741+12 may become 74(1+1)2, which is evaluated as 74 * (1 + 1) * 2 = 296. Placements such as (74)1+12 and 741(+12) are invalid. Return the smallest value obtainable from any valid placement of the parentheses. A solution with time complexity no worse than O(expr.length^4) will fit within the execution time limit. Function minimizeExpressionValueWithParentheses(expr: String) → int Examples Example 1 expr = "247+38" return = 170 Placing the parentheses as 2(47+38) gives 2 * 85 = 170, the smallest value among all valid placements. Example 2 expr = "12+34" return = 20 The placement 1(2+3)4 evaluates to 1 * 5 * 4 = 20, which is minimal. Example 3 expr = "999+999" return = 1998 Putting both complete numbers inside the parentheses yields (999+999) = 1998. Every placement with an outside factor is larger. Constraints expr contains exactly one plus sign. At least one digit appears on each side of the plus sign. Every digit in expr is between 1 and 9. Every value produced by a valid placement fits in a signed 32-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Split the string at the plus sign into left and right numbers. Pick a cut i in the left number (0 to len-1) and a cut j in the right number (1 to len). The left part before i is the outer left factor, the rest of the left number joins the sum. The right part up to j joins the sum, the remainder is the outer right factor. If a side is empty, its factor is 1. Compute factorLeft * (leftInside + rightInside) * factorRight and track the min. That's O(n^2) pairs, each with O(n) parsing, well inside the O(n^4) allowance. Pitfalls: forgetting the empty-string-means-1 rule, letting the parenthesis touch the plus sign, and overflow if you use a narrow type. Use long during evaluation. If you freeze on the indexing, StealthCoder can give you the loop skeleton live, but write it yourself if you can.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Minimize Expression Value with Parentheses (for mle also :) cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as minimize result by adding parentheses to expression. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass ByteDance's OA.
ByteDance reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimize Expression Value with Parentheses (for mle also :) FAQ
How hard is the ByteDance minimize expression OA really?+
Easy to medium. The constraint allows O(n^4), so you just enumerate every valid parenthesis placement and evaluate it. The difficulty is careful indexing and handling empty outer factors, not any clever algorithm.
What's the trick to this problem?+
There isn't a deep one. Split on the plus, loop over a left cut and a right cut, treat an empty outer side as 1, and take the minimum. The only real trick is keeping the parenthesis off the plus sign so each side keeps at least one digit.
What pattern is this?+
Brute-force enumeration over string split points. You're trying all valid pairs of positions and computing a value for each. It's string manipulation with simple arithmetic, no dynamic programming or greedy logic needed.
What edge cases break most solutions?+
Empty outer factors that should default to 1, parenthesis positions that touch the plus sign, and parsing empty substrings as numbers. Cases like 999+999 where the best answer puts everything inside the parentheses also catch people who force an outer factor.
How do I prepare for this in 48 hours?+
Write the solution once from scratch on your examples: 247+38 gives 170, 12+34 gives 20, 999+999 gives 1998. Then practice a few string-splitting problems so substring slicing and integer parsing feel automatic. That's enough for this one.