In the Construct String With Repeat Limit interview question, you are given a string and a repeatLimit. You need to use the characters from the string to construct the lexicographically largest possible string such that no character appears more than repeatLimit times in a row. You don't have to use all characters.
Microsoft and Google use the Construct String With Repeat Limit coding problem to test a candidate's greedy intuition. It requires a balance between picking the "best" (largest) character and satisfying a constraint. It also evaluates the ability to "save" characters for later use when a limit is reached.
This follows the Hash Table, Heap (Priority Queue), String, Greedy interview pattern.
String: "cczazcc", repeatLimit = 3
Whenever a problem involves "lexicographically largest" and frequency constraints, a Max-Heap combined with a greedy "breaker" strategy is almost always the answer.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Reorganize String | Medium | Solve | |
| Replace Question Marks in String to Minimize Its Value | Medium | Solve | |
| Construct K Palindrome Strings | Medium | Solve | |
| Largest Palindromic Number | Medium | Solve | |
| Rearrange String k Distance Apart | Hard | Solve |