Partition string into as many parts as possible so each letter appears in at most one part.

Input: s="ababcbacadefegdehijhklij" → Output: [9,7,8] Input: s="eccbbbbdec" → Output: [10]

Record last occurrence of each character. Expand current partition when current index equals its end.

public List<Integer> partitionLabels(String s) { int[] last = new int[26]; for (int i = 0; i < s.length(); i++) last[s.charAt(i) - 'a'] = i; List<Integer> result = new ArrayList<>(); int start = 0, end = 0; for (int i = 0; i < s.length(); i++) { end = Math.max(end, last[s.charAt(i) - 'a']); if (i == end) { result.add(end - start + 1); start = end + 1; } } return result; }