Given a string s, return the number of distinct non-empty subsequences of s. Since the answer may be very large, return it modulo 10^9 + 7. A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not.)
Example 1
Input: s = abc
Output: 7
Explanation: All 3 characters are distinct, so every non-empty subset is a distinct subsequence: "a", "b", "c", "ab", "ac", "bc", "abc" = 7.
Example 2
Input: s = aba
Output: 6
Explanation: The 6 distinct subsequences are "a", "b", "ab", "aa", "ba", "aba" — the repeated 'a' collapses would-be duplicates.
Example 3
Input: s = aaa
Output: 3
Explanation: Only lengths matter with all-equal characters: "a", "aa", "aaa" = 3.
Let dp[i] count the distinct subsequences (including the empty one) that can be formed from the first i characters. Appending the next character to every existing subsequence doubles the count, but that double-counts every subsequence the same character produced last time it appeared — subtract exactly that overlap.
Run checks all cases above. Submit evaluates all test cases.