Code Room
CodingMediumcod-g042
Subject GreedyLevel Mid–Senior~20 minCommon in Distributed systems · Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.