Count distinct substrings
Given a string s, count the number of distinct non-empty substrings of s. Insert every suffix of s into a trie; each trie node (other than the root) corresponds to exactly one distinct substring, so the answer is the total number of trie nodes created. Return that count. The string length is up to a few hundred, so the O(n^2) suffix-trie construction is acceptable.
Implement
count_distinct_substrings(s: str) → intExamples
in
["abab"]out7What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 30 min
solution.py
InputExpectedGot
["abab"]7not run yetsample