mediumGreedyAmazon
Letter Zone Splitter
A labeler splits a text into the maximum number of contiguous zones so that each character appears in only one zone.
Partition the string into as many parts as possible so that each letter appears in at most one part; return the sizes.
Choose approach
a
0i
b
1a
2b
3c
4b
5a
6c
7a
8end
d
9e
10f
11e
12g
13d
14e
15h
16i
17j
18h
19k
20l
21i
22j
23Setzones
empty
1/24
Narrationstep 1 of 24
i=0: end extends to 8.
Variables
i=0
end=8
start=0
zones=
How to think about it
- All letters' last-seen indices define zone bounds.
- Close zone when i matches the running max.
Edge cases to catch in interview
- Single char -> [1].
- All same char -> [length].
Examples
Example 1
[10]{"s":"eccbbbbdec","values":["e","c","c","b","b","b","b","d","e","c"]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed