Trains the technique from
LeetCode 763Partition LabelsThis 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 workshop posts its watch roster as roster, a string of lowercase letters. The letter in each slot is the code of the technician standing that watch, and the slots run left to right in the order they will be worked.
The supervisor wants to hand the roster out in consecutive blocks. Every slot belongs to exactly one block and the blocks stay in order, so reading the blocks one after another spells roster again. A block may only be handed out if no technician's code turns up in any other block. Split the roster into as many blocks as that allows, which fixes one answer.
Return the number of slots in each block, in the order the blocks are worked.
Example 1
The blocks are `zz`, `xyx`, `ww` and `v`, so their slot counts are 2, 3, 2 and 1. Codes z, x, y, w and v each sit inside one block only.
Example 2
The blocks are `aabbaa` and `cc`. Codes a and b are confined to the first block and code c to the second.
Example 3
No code repeats anywhere in the roster, and the four one-slot blocks each hold a different code.
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 duty_roster_blocks(roster: str) -> list[int]:public List<Integer> dutyRosterBlocks(String roster)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.