563. Distinct Substrings

Given a string s of length n, the task is to compute the number of distinct substrings that appear in the string. A substring is defined as a contiguous sequence of characters within the string.

The task is to determine how many unique substrings can be formed from the string.

Example 1:

Input: s = "abab"

Output: 7

Explanation:

The distinct substrings are:

"a", "b", "ab", "ba", "aba", "bab", "abab".

Example 2:

Input: s = "aaaa"

Output: 4

Explanation:

The distinct substrings are:

"a", "aa", "aaa", "aaaa".

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= s.length <= 103

Fun Facts

0
 
class Solution{
public:
int countDistinctSubstrings(string s){
}
};
Test Case

Input:

S