a
b
a
b
c
b
a
c
a
d
e
f
e
g
d
e
h
i
j
h
k
l
i
j
[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][22][23]
Greedy · cut at each letter’s last occurrence
▸1given s2for i ← 0 to n − 1: last[s[i]] ← i3start ← 0; end ← 0; sizes ← []4for i ← 0 to n − 1:5 end = max(end, last[s[i]])6 if i == end:7 sizes.push(end − start + 1); start ← i + 18return sizes
state
- n24
- s"ababcbacadefegdehijhklij"