MediumGreedy · Two Pointers · Hash Map

Partition Labels

Split the lowercase 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.

s = "xyxxyzbzbbisl" → [5,5,1,1,1] ("xyxxy", "zbzbb", "i", "s", "l")s = "abcabc" → [6]

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Variables

The data structures the code is building

The string

Bars = each letter from its first to its last copy

Time and space complexity

n = len(s), m = distinct letters. The highlighted row is the solution being traced.

Keyboard: ← → step, Space play or pause. Lowercase letters only; drawings use at most 24 letters.