Practice Distinct Subsequences II
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Count the distinct nonempty strings that can be obtained by deleting zero or more characters from s without changing the order of those retained. Equal resulting strings count once regardless of their selected positions. Return the count modulo 10^9 + 7.
Source: Distinct Subsequences II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
s = "abc"
Output
7
# Example 2
Input
s = "aba"
Output
6
# Example 3
Input
s = "aaa"
Output
3
Constraints
1 <= s.length <= 2000
s consists of lowercase English letters.
Related LeetCode Problems
Practice more problems similar to Distinct Subsequences II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.