Skip to content
Decoder

Partition Labels

Medium

Problem

Cut the string s into as many pieces as possible so that every letter appears in at most one piece. Return the sizes of the pieces, in order.

Example 1

Input
s = "abcabdde"
Output
[5, 2, 1]
Why
"abcab", "dd", "e"

Example 2

Input
s = "caedbdedda"
Output
[1, 9]
Why
"c", "aedbdedda"

Example 3

Input
s = "eccbbbbdec"
Output
[10]
Why
one piece holds everything

Constraints

  • 1 <= s.length <= 500
  • s contains only lowercase English letters.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.