CoolFace
Datasetpublic

TheRealSamuel/LeetCodeProblem

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes564downloads
1{2    "id": 2328,3    "name": "minimize_result_by_adding_parentheses_to_expression",4    "difficulty": "Medium",5    "link": "https://leetcode.com/problems/minimize-result-by-adding-parentheses-to-expression/",6    "date": "1648944000000",7    "task_description": "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. **Example 1:** ``` **Input:** expression = \"247+38\" **Output:** \"2(47+38)\" **Explanation:** The `expression` evaluates to 2 * (47 + 38) = 2 * 85 = 170. Note that \"2(4)7+38\" is invalid because the right parenthesis must be to the right of the `'+'`. It can be shown that 170 is the smallest possible value. ``` **Example 2:** ``` **Input:** expression = \"12+34\" **Output:** \"1(2+3)4\" **Explanation:** The expression evaluates to 1 * (2 + 3) * 4 = 1 * 5 * 4 = 20. ``` **Example 3:** ``` **Input:** expression = \"999+999\" **Output:** \"(999+999)\" **Explanation:** The `expression` evaluates to 999 + 999 = 1998. ``` **Constraints:** `3 <= expression.length <= 10` `expression` consists of digits from `'1'` to `'9'` and `'+'`. `expression` starts and ends with digits. `expression` contains exactly one `'+'`. 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.",8    "public_test_cases": [9        {10            "label": "Example 1",11            "input": "expression = \"247+38\"",12            "output": "\"2(47+38)\" "13        },14        {15            "label": "Example 2",16            "input": "expression = \"12+34\"",17            "output": "\"1(2+3)4\" "18        },19        {20            "label": "Example 3",21            "input": "expression = \"999+999\"",22            "output": "\"(999+999)\" "23        }24    ],25    "private_test_cases": [26        {27            "input": "69+1",28            "output": "6(9+1)"29        },30        {31            "input": "5+57888",32            "output": "(5+5788)8"33        },34        {35            "input": "2281+9868",36            "output": "(2281+9868)"37        },38        {39            "input": "718+2",40            "output": "7(18+2)"41        },42        {43            "input": "9+1776",44            "output": "(9+177)6"45        },46        {47            "input": "75+59239",48            "output": "(75+592)39"49        },50        {51            "input": "2+925",52            "output": "(2+9)25"53        },54        {55            "input": "3347+15",56            "output": "3(347+15)"57        },58        {59            "input": "89337+98",60            "output": "89(337+98)"61        },62        {63            "input": "376+635",64            "output": "(376+635)"65        }66    ],67    "haskell_template": "minimizeResult :: String -> String\nminimizeResult expression ",68    "ocaml_template": "let minimizeResult (expression: string) : string =  ",69    "scala_template": "def minimizeResult(expression: String): String = { \n    \n}",70    "java_template": "public static String minimizeResult(String expression) {\n\n}",71    "python_template": "class Solution(object):\n    def minimizeResult(self, expression):\n        \"\"\"\n        :type expression: str\n        :rtype: str\n        \"\"\"\n        "72}