All problems
Partition Labels
Problem
Partition the string s into as many parts as possible so that each letter appears in at most one part, and return the list of part lengths.
Record the last index of every character, then extend the current part's end until the scan reaches it before cutting. The parts are returned in order.
Hint
A part can only end at an index that is the last occurrence of every letter seen so far.
Test cases
case 1
in: ["ababcbacadefegdehijhklij"]
expected: [9,7,8]
case 2
in: ["eccbbbbdec"]
expected: [10]
case 3
in: ["a"]
expected: [1]
case 4
in: [""]
expected: []
case 5
in: ["abac"]
expected: [3,1]
Starter codePython
def partition_labels(s):
# Your code here
pass5 test cases · run your code against them in the editor