count
of size 26 to store the length of the longest contiguous substring ending with each alphabet character.maxLengthCur
to 0, which will store the length of the current contiguous substring.c
in the input string s
.
a. If c
is the next character in the wraparound string after the previous character, increment maxLengthCur
.
b. Otherwise, reset maxLengthCur
to 1.
c. Calculate the index i
for c
in the alphabet (0 for 'a', 1 for 'b', ..., 25 for 'z').
d. Update count[i]
to the maximum of its current value and maxLengthCur
.count
to get the total number of unique substrings.