Determine Minimum Characters to Append
Problem statement
You are given two strings, searchWord and resultWord. You may append characters only to the end of searchWord. Return the minimum number of characters that must be appended so that resultWord is a subsequence of the resulting searchWord.
A subsequence is formed by deleting zero or more characters without changing the order of the remaining characters. Equivalently, match the longest prefix of resultWord as a subsequence of searchWord; the unmatched suffix of resultWord is what must be appended.
Function
minCharactersToAppend(searchWord: String, resultWord: String) → intExamples
Example 1
searchWord = "abcz"resultWord = "azdb"return = 2The prefix az of resultWord appears in order in searchWord at indices 0 and 3. The unmatched suffix is db, whose length is 2. Appending it produces abczdb, which contains azdb as a subsequence.
Constraints
1 <= searchWord.length, resultWord.length <= 100000- Both strings contain only lowercase English letters.