Code RoomPartition labels by character occurrence
MediumPrep Room Coding #99

Partition labels by character occurrence

CodingDistributed systemsAlgorithms & data structuresMid–Senior~20 min

You are given a string s of lowercase English letters. Partition it into as many contiguous parts as possible so that each letter appears in at most one part. Return a list of the sizes of these parts, in left-to-right order. The string has length between 1 and 500.

Implement
partition_labels(s: str) → list[int]
Examples
in["ababcbacadefegdehijhklij"]out[9,7,8]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 20 min
InputExpectedGot
["ababcbacadefegdehijhklij"][9,7,8]not run yetsample