Description

Given a string s, partition it so that each letter appears in at most one part. Return a list of integers representing the size of these parts.

Examples

Input:s = "ababcbacadefegdehijhklij"
Output:[9,7,8]
Explanation:

Partition is "ababcbaca", "defegde", "hijhklij".

Input:s = "abcabc"
Output:[6]
Explanation:

All three letters 'a', 'b', and 'c' appear throughout the entire string. Since 'a' appears at positions 0 and 3, 'b' appears at positions 1 and 4, and 'c' appears at positions 2 and 5, it is not possible to split the string without having at least one letter appear in multiple parts. Therefore, the entire string must be one partition of length 6.

Input:s = "abcdefg"
Output:[1,1,1,1,1,1,1]
Explanation:

Each letter appears exactly once in the string, so each letter can form its own partition. It is possible to split after every character: 'a', 'b', 'c', 'd', 'e', 'f', 'g', resulting in 7 partitions each of size 1.

Constraints

  • 1 ≤ s.length ≤ 500
  • s consists of lowercase English letters.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!