Partition Labels

You are given a string s. Partition the string into as many parts as possible so that each letter appears in at most one part.

Note that the partition is done so that after concatenating all the parts in order, the resultant string should be s.

Return a list of integers representing the size of these parts.

Example 1
Inputs = "ababcbacadefegdehijhklij"
Output[9,7,8]
The partition is "ababcbaca", "defegde", "hijhklij", so each letter appears in at most one part and the number of parts is maximized.
Example 2
Inputs = "eccbbbbdec"
Output[10]
The entire string must remain one part because its letters overlap across the whole string.

Constraints

  • 1 <= s.length <= 500
  • s consists of lowercase English letters.

Asked at 9 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate