lastSeen
of size 26 to -1
to keep track of the most recent position of each character.count
to 1
as we start with the first substring.substringStart
to 0
to mark the beginning of the current substring.s
and for each character at index i
:
lastSeen[s[i] - 'a']
with substringStart
.count
, start a new substring, and update substringStart
to i
.lastSeen[s[i] - 'a']
to i
.count
.