You're given two strings s and t, and your goal is to transform t into a subsequence of s by removing some characters from t.
Here's the challenge: minimize the "removal cost" of making this transformation!
How scoring works:
- If you don't remove any characters: score =
0 - If you remove characters at indices
left(minimum) toright(maximum): score =right - left + 1
The key insight is that you want to remove characters in the most compact range possible. For example, removing characters at indices [2,3,4] costs 3, while removing [1,5,9] costs 9!
Goal: Return the minimum possible score to make t a subsequence of s.
Remember: A subsequence maintains the relative order of characters, like "ace" from "abcde".
Input & Output
Visualization
Time & Space Complexity
O(n) preprocessing + O(log n) binary search iterations ร O(n) validation per iteration
Space for left and right prefix arrays
Constraints
- 1 โค s.length, t.length โค 105
- s and t consist of only lowercase English letters
- Memory limit: 256 MB