Practice Minimize Result by Adding Parentheses to Expression
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given a 0-indexed string expression of the form "<num1>+<num2>" where <num1> and <num2> represent positive integers. Add a pair of parentheses to expression such that after the addition of parentheses, expression is a valid mathematical expression and evaluates to the smallest possible value. The left parenthesis must be added to the left of '+' and the right parenthesis must be added to the right of '+'. Return expression after adding a pair of parentheses such that expression evaluates to the smallest possible value. If there are multiple answers that yield the same result, return any of them. The input has been generated such that the original value of expression, and the value of expression after adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer.
Source: Minimize Result by Adding Parentheses to Expression on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
expression = "247+38"
"2(47+38)"
# Example 2
expression = "12+34"
"1(2+3)4"
# Example 3
expression = "999+999"
"(999+999)"
Constraints
Related LeetCode Problems
Practice more problems similar to Minimize Result by Adding Parentheses to Expression.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.