Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Number of Distinct Substrings in a String
Bookmark
Brute Force
Suffix Trie
Rolling Hash
Input
"abc" → 6
"aab" → 5
"abab" → 7
Custom
s
=
abc
a
b
c
0
1
2
seen (substrings)
set size
0
a
b
c
0
1
2
seen (substrings)
set size
0
a
b
c
i
0
1
2
seen (substrings)
set size
0
a
b
c
i
j
0
1
2
seen (substrings)
a
substring
"a"
set size
1
a
b
c
i
j
0
1
2
seen (substrings)
a
ab
substring
"ab"
set size
2
a
b
c
i
j
0
1
2
seen (substrings)
a
ab
abc
substring
"abc"
set size
3
a
b
c
i
j
0
1
2
seen (substrings)
a
ab
abc
set size
3
a
b
c
i
j
0
1
2
seen (substrings)
a
ab
abc
b
substring
"b"
set size
4
a
b
c
i
j
0
1
2
seen (substrings)
a
ab
abc
b
bc
substring
"bc"
set size
5
a
b
c
i
j
0
1
2
seen (substrings)
a
ab
abc
b
bc
substring
"c"
set size
5
a
b
c
0
1
2
seen (substrings)
a
ab
abc
b
bc
c
set size
6
algo
master
.
io
Step:
Start: Collect every substring in a set and count what survives
0 / 17
Input
"abc" → 6
"aab" → 5
"abab" → 7
Custom
s
=
abc
0 / 17
algo
master
.
io
Step:
Start: Collect every substring in a set and count what survives