Problem
You get two strings s and t. Return the number of distinct subsequences of s that are equal to t.
A subsequence of s is a string that you get when you remove zero or more characters from s. The remaining characters keep their order.
Two subsequences are distinct when they use different sets of positions in s. The answer fits in a signed 32-bit integer.
Example 1
- Input:
- s = "banana", t = "ban"
- Output:
- 3
- Explanation:
- The
bis at index 0. Theaand thenare at indexes 1 and 2, at 1 and 4, or at 3 and 4.
Example 2
- Input:
- s = "aaa", t = "aa"
- Output:
- 3
- Explanation:
- Any 2 of the 3 positions give
"aa".
Example 3
- Input:
- s = "abc", t = "abcd"
- Output:
- 0
- Explanation:
tis longer thans, so no subsequence ofsis equal tot.
Constraints
- 1 <= s.length, t.length <= 1000
- s and t have only English letters.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Decode Ways
Coding · Dynamic Programming · String
- Generate Parentheses
Coding · Backtracking · Bracket Sequences · Dynamic Programming
- Longest Common Subsequence
Coding · Dynamic Programming · Longest Common Subsequence · String
- Longest Palindromic Subsequence
Coding · Dynamic Programming · String
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 115. Distinct Subsequences
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 2 records
Swiggy
Distinct Subsequences
Reported date not specified · Source window: 3mo
Source snapshot: Oct 20, 2026
Source frequency score: 100. This is not an interview probability.
View sourceSwiggy
Distinct Subsequences
Reported date not specified · Source window: 6mo
Source snapshot: Oct 20, 2026
Source frequency score: 100. This is not an interview probability.
View source