Leetcode Problem 1698. Number of Distinct Substrings in a String
1698. Number of Distinct Substrings in a String
AI Mock Interview
Leetcode Solutions
Suffix Array and Longest Common Prefix (LCP)
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Construct the suffix array for the string
s
using the Manber-Myers algorithm.
Compute the LCP array using the Kasai algorithm.
Calculate the total number of possible substrings of
s
, which is
n * (n + 1) / 2
, where
n
is the length of
s
.
Subtract the sum of the LCP array from the total number of possible substrings to get the number of distinct substrings.
Trie-based Substring Counting
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...