Distinct Subsequences
Given two strings s and t, return the number of distinct subsequences of s that equal t. A subsequence keeps the original order of characters but may skip any of them. Two subsequences are different if they use different positions of s, even when the resulting text is the same.
For example, "rabbit" can be taken from "rabbbit" in 3 ways, one for each b that is left out.
The empty string t can be formed in exactly one way (choose nothing). The answer fits in a 32-bit signed integer.
Constraints
0 <= s.length, t.length <= 1000sandtconsist of English letters.
Examples
Example 1
Input: s = "rabbbit", t = "rabbit" Output: 3
Drop any one of the three b's from "rabbbit": 3 ways to spell "rabbit".
Example 2
Input: s = "babgbag", t = "bag" Output: 5
There are 5 ways to pick a b, then an a, then a g in order.
Example 3
Input: s = "abc", t = "" Output: 1
The empty string can be formed in exactly one way: pick nothing.
JavaScript you'll use: Strings and characters Arrays: create, read, update
/**
* @param {string} s
* @param {string} t
* @return {number}
*/
function numDistinct(s, t) {
}
Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.