InferenceAI

Enter at least two characters to search.

Start free

Partition Labels

mediumGreedy & Intervals25 min25 XP

Split s into as many parts as possible so each letter appears in at most one part. Return the sizes of the parts, in order.

Examples

EXAMPLE WALKTHROUGHclassic

A guided view of the published example, not a trace of your code.

INPUT["ababcbacadefegdehijhklij"]
TASKpartition_labels()
EXPECTED OUTPUT[9,7,8]

Start with the input values shown in this example.

Example 1 of 3

Input: s = "ababcbacadefegdehijhklij"

Output: [9,7,8]

Explanation: classic

Input: s = "eccbbbbdec"

Output: [10]

Explanation: one part

Input: s = "abc"

Output: [1,1,1]

Explanation: all distinct

Hint 1

Record each letter's last index; a part ends when the current index reaches the furthest last index seen in it.

Topics

DSAGreedy & IntervalsPython