Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes399downloads
construct-smallest-number-from-di-string.json32 linesDownload Raw Back to root
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": "2022-08-07",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  "test_case": [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  "constraints": [21    "num consists of the digits '1' to '9', where each digit is used at most once.",22    "If pattern[i] == 'I', then num[i] < num[i + 1].",23    "If pattern[i] == 'D', then num[i] > num[i + 1].",24    "1 <= pattern.length <= 8",25    "pattern consists of only the letters 'I' and 'D'."26  ],27  "python_template": "class Solution(object):\n    def smallestNumber(self, pattern):\n        \"\"\"\n        :type pattern: str\n        :rtype: str\n        \"\"\"\n        ",28  "java_template": "class Solution {\n    public String smallestNumber(String pattern) {\n        \n    }\n}",29  "metadata": {30    "func_name": "smallestNumber"31  }32}