Given a string s, return the number of distinct non-empty subsequences of s. Pattern focus: Distinct subsequences. This is the one-string counting variant where duplicate characters force careful state compression.
s = input string
number of distinct non-empty subsequences
Example 1:
Input:
s = "abc"
Output:
7
Explanation:
All non-empty subsequences are distinct.
Example 2:
Input:
s = "aaa"
Output:
3
Explanation:
The distinct subsequences are a, aa, and aaa.