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 the parts in order, the resultant string should be s.
Return a list of integers representing the size of these parts.
Greedy Insight: For each character, find its last occurrence. As we scan, maintain the farthest "end" we must reach before we can make a partition. When current index equals the end, we've found a partition.
Why Greedy Works: A character must appear entirely within one partition. By tracking the last occurrence of each character in the current partition, we know the minimum endpoint. When we reach it, all characters so far are contained, so we greedily partition.
s = "ababcbacadefegdehijhklij"[9,7,8]s = "eccbbbbdec"[10]1 <= s.length <= 500s consists of lowercase English letters.Click "Run" to execute your code against test cases
Socratic guidance - I'll ask questions, not give answers