Explanation
Partition Labels is a Medium interview problem tagged [Hash Table, String, Greedy, Two Pointers]. The winning approach is typically **Greedy**.
#763
You are given a string s. We want to partition the string into as many parts as possible so that each letter appears in at most one part.
Note that the partition is done so that after concatenating all parts in order, the resultant string should be s.
Return a list of integers representing the size of these parts.
Example 1
Input: s = "ababcbacadefegdehijhklij"
Output: [9,7,8]
Partition as ababcbaca / defegde / hijhklij.
Example 2
Input: s = "eccbbbbdec"
Output: [10]
All letters share one partition.
Partition Labels is a Medium interview problem tagged [Hash Table, String, Greedy, Two Pointers]. The winning approach is typically **Greedy**.
When an exchange argument holds, greedy beats heavier DP.
Sort by a key, then make the locally best choice that preserves a global invariant.
Pattern-level skeleton only — not this problem’s exact answer. Adapt it to the statement.
Time: O(n log n) or O(n)
Space: O(n)
Before coding, restate the problem, name the pattern (Greedy), and write the invariant or DP state in one sentence.
Got it?
Mark #763 Partition Labels as understood when the pattern clicks.