Trains the technique from
LeetCode 451Sort Characters By FrequencyThis 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 print shop peels stickers off a sheet one after another and reads them out as a single string sheet. Each sticker carries one English letter or one digit. Upper case and lower case are different stock, so w and W are two unrelated stickers.
Lay the sheet out again so that all copies of a sticker sit next to each other in one unbroken block, and so that a block of a sticker peeled more often comes before a block of a sticker peeled less often. Every sticker from the original sheet appears in the answer, as many times as it was peeled.
When two stickers were peeled the same number of times, the one whose first copy appeared earlier in sheet gets the earlier block. That rule fixes a single correct answer, so return it as a string.
Example 1
Both `i` and `s` were peeled four times, and the first `i` came before the first `s`, so the `i` block leads; then `p` with two and `m` with one.
Example 2
The digit `2` was peeled twice so its block leads, and `R` and `D` tie at one each and keep the order in which they first showed up.
Example 3
All four stickers are distinct stock peeled once each, so the tie rule keeps the sheet exactly as it was read.
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 regroup_stickers(sheet: str) -> str:public String regroupStickers(String sheet)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.