Skip to content

Practice Construct String With Repeat Limit

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2182
LeetCode Problem

Construct String With Repeat Limit

Problem Statement

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.

Source: Construct String With Repeat Limit on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "cczazcc", repeatLimit = 3
Output
"zzcccac"

# Example 2

Input
s = "aababab", repeatLimit = 2
Output
"bbabaa"

Constraints

1 <= repeatLimit <= s.length <= 10^5
s consists of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Construct String With Repeat Limit.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.