Distinct Subsequences
Given two strings s and t, return the number of distinct subsequences of s that equal t. A subsequence is formed by deleting zero or more characters of s without changing the order of the remaining characters. The answer fits in a 32-bit signed integer.
Open official problem prompt ↗Count how many distinct order-preserving selections of characters in s spell out t exactly.
Imagine t is a word you must spell using beads threaded on a string s in fixed order. You may skip beads but not reorder them. The task is to count how many different sets of beads spell the word.
- Input
- s = "rabbbit", t = "rabbit"
- Output
- 3
- Why
- There are three ways to keep r-a-b-b-i-t by choosing which two of the three b's to use.
1 <= s.length, t.length <= 1000s and t consist of English lettersThe answer is guaranteed to fit in a 32-bit signed integer