Browser tab content: Problem List 0 Debugging... Run Submit 00:00:00 Description…
- User
Browser tab content: Problem List 0 Debugging... Run Submit 00:00:00 Description Editorial Editorial Solutions Solutions Submissions Submissions Code Note Note Testcase Testcase Test Result 115. Distinct Subsequences Hard Topics Companies
Given two strings s and t, return the number of distinct subsequences of s which equals t.
The test cases are generated so that the answer fits on a 32-bit signed integer.
Example 1:
Input: s = "rabbbit", t = "rabbit" Output: 3 Explanation: As shown below, there are 3 ways you can generate "rabbit" from s. rabbbit rabbbit rabbbit
Example 2:
Input: s = "babgbag", t = "bag" Output: 5 Explanation: As shown below, there are 5 ways you can generate "bag" from s. babgbag babgbag babgbag babgbag babgbag
Constraints:
1 <= s.length, t.length <= 1000 s and t consist of English letters. Seen this question in a real interview before? 1/5 Yes No Accepted 464.9K Submissions 957.1K Acceptance Rate 48.6% Topics String Dynamic Programming Companies 0 - 3 months Amazon 3 Microsoft 2 Oracle 2 Trilogy 2 0 - 6 months Google 2 6 months ago TikTok 6 Uber 4 Bloomberg 3 Adobe 3 Apple 3 Salesforce 3 MathWorks 2 Similar Questions Number of Unique Good Subsequences Hard Discussion (113) Choose a type Preview Comment 💡 Discussion Rules
-
Please don't post any solutions in this discussion.
-
The problem discussion is for asking questions about the problem or for sharing tips - anything except for solutions.
-
If you'd like to share your solution for feedback and ideas, please head to the solutions tab and post it there.
Sort by:Best No comments yet. 1 2 3 4 5 6 12 Copyright ©️ 2024 LeetCode All rights reserved 6.8K 113 Java Auto 1 2 3 4 5 class Solution { public int numDistinct(String s, String t) { } } Saved Ln 1, Col 1 You must run your code first
Find the Index of the First Occurrence in a String - LeetCode
Problem List Tag 41. First Missing Positive
Hard
- Trapping Rain Water
Hard
- Multiply Strings
Med.
- Wildcard Matching
Hard
- Jump Game II
Med.
- Permutations
Med.
- Permutations II
Med.
- Rotate Image
Med.
- Group Anagrams
Med.
- Pow(x, n)
-
- Assistant
To solve the problem of finding the number of distinct subsequences of string
sthat equal stringt, a dynamic programming approach is generally used. Here's a clean, common, and optimized Java solution that efficiently addresses this problem: