Given two strings, searchWord and resultWord:
Determine the minimum number of characters you need to append to resultWord so that it becomes a subsequence of searchWord.
Example:
Input: searchWord = "abcz" resultWord = "azdb"
Output: 2
Explanation: By appending 'd' and 'b' to "azdb", we can transform it into a subsequence of "abcz".
Understanding the Problem:
A subsequence of a string is derived by deleting some or no characters from it without changing the order of the remaining characters. For example:
"ace" is a subsequence of "abcde" because 'a', 'c', and 'e' appear in order.
"ace" is NOT a subsequence of "abcde" because 'e' appears before 'c'.
In this problem:
Input: Two strings, searchWord and resultWord.
Output: The number of characters to append to resultWord so that all characters in resultWord appear in order as a subsequence in searchWord.
searchWord = "abcz" resultWord = "azdb" return = 2
By appending 'd' and 'b' to "azdb", we can transform it into a subsequence of "abcz".
🐇- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int minCharactersToAppend(String searchWord, String resultWord) {
// write your code here
}