Distinct Subsequences

Given nonempty source str1 and target str2, count the increasing source-index selections whose characters spell the entire target. Different selections count…

Given nonempty source str1 and target str2, count the increasing source-index selections whose characters spell the entire target. Different selections count separately even when they spell identical text. Return the count modulo 1,000,000,007. Characters are Unicode scalar values, not UTF-8 bytes, UTF-16 code units, or visual grapheme clusters. Do not normalize, trim, or change case. Unpaired surrogates are outside the input domain.

- 1 <= Unicode-scalar length of each operand <= 1000. - All Unicode scalar values; no unpaired surrogates or normalization. - The visualizer accepts each operand up to 8 scalars; longer valid inputs are coding-only.

Example 1: input str1 = "peep", str2 = "pep"; output 2. For peep and pep, select indices 0,1,3 or 0,2,3. Both spell pep, so the answer is 2, not 1.

Example 2: input str1 = "aaaaaa", str2 = "aaa"; output 20. Choose three of the six source positions: there are 20 increasing selections.

Example 3: input str1 = "ab", str2 = "ba"; output 0. No valid shared match satisfies the stated ordering and character conditions.

Category: Strings. Topic: dynamic-programming. Difficulty: hard. Patterns: dynamic-programming.