Partition Labels
Given a string s, partition it into as many parts as possible so that each letter appears in at most one part. Return the sizes of these parts as a list of integers, in left-to-right order.
The tests print the returned sizes as space-separated integers.
Example
ababcbacadefegdehijhklij
9 7 8
- The input
shas 24 lowercase letters at positions to . The output lists part lengths from left to right. - Every copy of a letter must land in the same part. The first
ais at position and the last at position , so the first part covers at least positions to . Inside that span,bandclast appear at and , so nothing crosses the boundary and the first part isababcbaca, length . - The second part starts with
d(last copy at ), and it containse, whose last copy is at . Nothing in positions to reaches further, givingdefegde, length . - The final part
hijhklijcovers positions to , length , becausejappears again at the very end. - Notice that . The parts tile the whole string, and each cut is made as early as the letters allow, which is what makes the number of parts as large as possible.
Constraints
- 1 <= len(s) <= 500
- s consists of lowercase English letters