You are given two strings s and t consisting of only lowercase English letters.
Your task is to find the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of the modified string.
A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
Example: If s = "coaching" and t = "coding", we need to append 2 characters because "coaching" already contains "co" as a subsequence, but we need to add "ding" to get the full "coding" subsequence.
Input & Output
Visualization
Time & Space Complexity
We generate 2^n subsequences where n is length of s, and for each we compare with t of length m
We need to store all possible subsequences
Constraints
- 1 โค s.length, t.length โค 105
- s and t consist only of lowercase English letters
- Follow-up: Can you solve this in O(n + m) time and O(1) space?