Search⌘ K
AI Features

Solution: Distinct Subsequences

Explore how to solve the distinct subsequences problem using dynamic programming in Go. This lesson guides you through implementing an efficient algorithm to count the exact matches of subsequences within two strings. You will understand the use of 1D DP array optimization and how to balance time and space complexity effectively.

Statement

Given two strings, s and t, determine how many distinct subsequences of s match t exactly.

Note: A subsequence is formed by deleting zero or more characters from s without changing the relative order of the remaining characters.

You may assume the result will always fit within a 3232-bit signed integer.

Constraints:

  • 11 \leq s.length, t.length 1000\leq 1000 ...