CoolFace
Datasetpublic

TheRealSamuel/LeetCodeProblem

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes564downloads
1{2    "id": 2456,3    "name": "construct_smallest_number_from_di_string",4    "difficulty": "Medium",5    "link": "https://leetcode.com/problems/construct-smallest-number-from-di-string/",6    "date": "1659830400000",7    "task_description": "You are given a **0-indexed** string `pattern` of length `n` consisting of the characters `'I'` meaning **increasing** and `'D'` meaning **decreasing**. A **0-indexed** string `num` of length `n + 1` is created using the following conditions: `num` consists of the digits `'1'` to `'9'`, where each digit is used **at most** once. If `pattern[i] == 'I'`, then `num[i] < num[i + 1]`. If `pattern[i] == 'D'`, then `num[i] > num[i + 1]`. Return _the lexicographically **smallest** possible string _`num`_ that meets the conditions._ **Example 1:** ``` **Input:** pattern = \"IIIDIDDD\" **Output:** \"123549876\" **Explanation: **At indices 0, 1, 2, and 4 we must have that num[i] < num[i+1]. At indices 3, 5, 6, and 7 we must have that num[i] > num[i+1]. Some possible values of num are \"245639871\", \"135749862\", and \"123849765\". It can be proven that \"123549876\" is the smallest possible num that meets the conditions. Note that \"123414321\" is not possible because the digit '1' is used more than once. ``` **Example 2:** ``` **Input:** pattern = \"DDD\" **Output:** \"4321\" **Explanation:** Some possible values of num are \"9876\", \"7321\", and \"8742\". It can be proven that \"4321\" is the smallest possible num that meets the conditions. ``` **Constraints:** `1 <= pattern.length <= 8` `pattern` consists of only the letters `'I'` and `'D'`.",8    "public_test_cases": [9        {10            "label": "Example 1",11            "input": "pattern = \"IIIDIDDD\"",12            "output": "\"123549876\" "13        },14        {15            "label": "Example 2",16            "input": "pattern = \"DDD\"",17            "output": "\"4321\" "18        }19    ],20    "private_test_cases": [21        {22            "input": "DIDDIIII",23            "output": "215436789"24        },25        {26            "input": "IDIDDI",27            "output": "1326547"28        },29        {30            "input": "DDD",31            "output": "4321"32        },33        {34            "input": "IIIII",35            "output": "123456"36        },37        {38            "input": "IIDDIDD",39            "output": "12543876"40        },41        {42            "input": "IDIDDD",43            "output": "1327654"44        },45        {46            "input": "I",47            "output": "12"48        },49        {50            "input": "III",51            "output": "1234"52        },53        {54            "input": "DDDIIDI",55            "output": "43215768"56        },57        {58            "input": "II",59            "output": "123"60        }61    ],62    "haskell_template": "smallestNumber :: String -> String\nsmallestNumber pattern ",63    "ocaml_template": "let smallestNumber (pattern: string) : string =  ",64    "scala_template": "def smallestNumber(pattern: String): String = { \n    \n}",65    "java_template": "public static String smallestNumber(String pattern) {\n\n}",66    "python_template": "class Solution(object):\n    def smallestNumber(self, pattern):\n        \"\"\"\n        :type pattern: str\n        :rtype: str\n        \"\"\"\n        "67}