Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes194downloads
construct-string-with-repeat-limit.json29 linesDownload Raw Back to root
1{2  "id": 2300,3  "name": "construct-string-with-repeat-limit",4  "difficulty": "Medium",5  "link": "https://leetcode.com/problems/construct-string-with-repeat-limit/",6  "date": "2022-02-13",7  "task_description": "You are given a string `s` and an integer `repeatLimit`. Construct a new string `repeatLimitedString` using the characters of `s` such that no letter appears **more than** `repeatLimit` times **in a row**. You do **not** have to use all characters from `s`. Return _the **lexicographically largest** _`repeatLimitedString` _possible_. A string `a` is **lexicographically larger** than a string `b` if in the first position where `a` and `b` differ, string `a` has a letter that appears later in the alphabet than the corresponding letter in `b`. If the first `min(a.length, b.length)` characters do not differ, then the longer string is the lexicographically larger one. **Example 1:** ``` **Input:** s = \"cczazcc\", repeatLimit = 3 **Output:** \"zzcccac\" **Explanation:** We use all of the characters from s to construct the repeatLimitedString \"zzcccac\". The letter 'a' appears at most 1 time in a row. The letter 'c' appears at most 3 times in a row. The letter 'z' appears at most 2 times in a row. Hence, no letter appears more than repeatLimit times in a row and the string is a valid repeatLimitedString. The string is the lexicographically largest repeatLimitedString possible so we return \"zzcccac\". Note that the string \"zzcccca\" is lexicographically larger but the letter 'c' appears more than 3 times in a row, so it is not a valid repeatLimitedString. ``` **Example 2:** ``` **Input:** s = \"aababab\", repeatLimit = 2 **Output:** \"bbabaa\" **Explanation:** We use only some of the characters from s to construct the repeatLimitedString \"bbabaa\". The letter 'a' appears at most 2 times in a row. The letter 'b' appears at most 2 times in a row. Hence, no letter appears more than repeatLimit times in a row and the string is a valid repeatLimitedString. The string is the lexicographically largest repeatLimitedString possible so we return \"bbabaa\". Note that the string \"bbabaaa\" is lexicographically larger but the letter 'a' appears more than 2 times in a row, so it is not a valid repeatLimitedString. ``` **Constraints:** `1 <= repeatLimit <= s.length <= 105` `s` consists of lowercase English letters.",8  "test_case": [9    {10      "label": "Example 1",11      "input": "s = \"cczazcc\", repeatLimit = 3",12      "output": "\"zzcccac\" "13    },14    {15      "label": "Example 2",16      "input": "s = \"aababab\", repeatLimit = 2",17      "output": "\"bbabaa\" "18    }19  ],20  "constraints": [21    "1 <= repeatLimit <= s.length <= 105",22    "s consists of lowercase English letters."23  ],24  "python_template": "class Solution(object):\n    def repeatLimitedString(self, s, repeatLimit):\n        \"\"\"\n        :type s: str\n        :type repeatLimit: int\n        :rtype: str\n        \"\"\"\n        ",25  "java_template": "class Solution {\n    public String repeatLimitedString(String s, int repeatLimit) {\n        \n    }\n}",26  "metadata": {27    "func_name": "repeatLimitedString"28  }29}