Given a string consisting of lower case English alphabets, the task is to find the number of distinct subsequences of the string
Note: Answer can be very large, so, ouput will be answer modulo 109+7
Input: s = "gfg"
Explanation: The seven distinct
subsequences are "", "g", "f", "gf", "fg",
"gg" and "gfg"
Input: s = "ggg"
Explanation: The four distinct
subsequences are "", "g", "gg", "ggg"
You do not need to read any input or print anything. The task is to complete the function distinctSubsequences(), which takes a string as input and returns an integer.
Expected Time Complexity: O(|str|)
Expected Auxiliary Space: O(|str|)
1 ≤ |s| ≤ 105
s contains lower case English alphabets
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
want to view the editorial?
Login to access your submissions.