Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 115 Distinct Subsequences - Problem Statement

LeetCode 115

Solve Distinct Subsequences from LeetCode. Given strings ss and tt, count distinct subsequences of ss that equal tt. This is counting DP. dp[i][j]dp[i][j] = ways to form t[0..j1]t[0..j-1] from s[0..i1]s[0..i-1].

If characters match, you can use it or skip it. If they don't match, you must skip. For ss = 'rabbbit' and tt = 'rabbit', there are 33 ways to choose which extra 'b' to drop.