Tap here to switch tabs
Problem
Submissions

Problem: Construct String With Repeat Limit

med
30 min
Try to solve the Construct String With Repeat Limit problem.

Statement

You are given a string s and an integer repeatLimit. Construct a new string using characters from s such that no character appears more than repeatLimit times consecutively. You do not need to use all the characters from s.

Return the lexicographically largest string that can be formed under this condition.

A string a is lexicographically larger than a string b if, at the first position where they differ, string a has a letter that appears later in the alphabet than the corresponding letter in b, or if b is a prefix of a and a is longer.

Constraints:

  • 1≤1 \leq repeatLimit ≤\leq s.length ≤105\leq 10^5

  • s consists of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Construct String With Repeat Limit

med
30 min
Try to solve the Construct String With Repeat Limit problem.

Statement

You are given a string s and an integer repeatLimit. Construct a new string using characters from s such that no character appears more than repeatLimit times consecutively. You do not need to use all the characters from s.

Return the lexicographically largest string that can be formed under this condition.

A string a is lexicographically larger than a string b if, at the first position where they differ, string a has a letter that appears later in the alphabet than the corresponding letter in b, or if b is a prefix of a and a is longer.

Constraints:

  • 1≤1 \leq repeatLimit ≤\leq s.length ≤105\leq 10^5

  • s consists of lowercase English letters.