text. A piece is any non-empty contiguous part of it, that is, what remains after removing some characters from the start and some from the end (possibly none).
Return how many distinct strings appear among the pieces. Identical pieces found in different places count only once.
A straightforward solution is easy to see; try to find one that does not store every piece in full.text='abab' → 7
The distinct pieces are "a", "b", "ab", "ba", "aba", "bab" and "abab": seven of them. Repeats of "a", "b" and "ab" count once.
text='zzz' → 3
Only "z", "zz" and "zzz".
text='abc' → 6
text.length ≤ 500text consists of lowercase English letterstext='abab'
7
Run checks the first 3 tests in your browser. Submit checks all 87 tests on the server, hidden ones included.