Trains the technique from
LeetCode 2182Construct String With Repeat LimitThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A signmaker owns a tray of letter tiles. The string tiles spells out what the tray holds, one lowercase letter per tile, so a letter that appears four times in tiles means four separate tiles carrying that letter.
The signmaker lays tiles left to right to spell a banner. Each tile may be used at most once, tiles may be left in the tray, and the banner must never show the same letter more than run_cap times in a row. A letter may still appear more than run_cap times in the banner overall, as long as no unbroken stretch of it is longer than run_cap.
Return the lexicographically largest banner the signmaker can spell. Banner x is lexicographically larger than banner y when either y is a proper prefix of x, or at the first position where the two differ x shows the letter that comes later in the alphabet.
Example 1
The banner uses every tile in the tray and no letter runs for more than two positions: the stretches are `cc`, `b`, `c`, `a`.
Example 2
The tray holds nothing but `z`, and a third `z` would make a run of three, so two tiles stay in the tray.
Example 3
Reading the banner, the runs are `ddd`, `c`, `d`, `c`. None is longer than three and all six tiles are used.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def largest_banner(tiles: str, run_cap: int) -> str:public String largestBanner(String tiles, int runCap)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.