Skip to content
Onsite

Partition Labels

MediumP2Coding

Split the string s into as many parts as possible so that each letter appears in at most one part. Return the sizes of the parts, in order. The parts, concatenated, must give back s.

Example 1

Input
s = "ababcbacadefegdehijhklij"
Output
[9,7,8]
Why
The parts are "ababcbaca", "defegde" and "hijhklij".

Example 2

Input
s = "eccbbbbdec"
Output
[10]

Constraints

  • 1 <= s.length <= 500
  • s consists of lower-case English letters

Hints

Run checks the 3 visible tests, Submit all 9.