#K15626. Minimum Deletions to Form Target Subsequence
Minimum Deletions to Form Target Subsequence
Minimum Deletions to Form Target Subsequence
You are given two strings S and T such that by removing some characters from S (possibly none) you can obtain T as a subsequence. Your task is to determine the minimum number of characters that need to be deleted from S so that the resulting string contains exactly the characters of T (in the original order).
In other words, if you remove characters from S so that the final string becomes T, you are required to delete as few characters as possible. It can be shown that the answer is given by:
where \(|S|\) and \(|T|\) denote the lengths of S and T respectively.
Note: It is guaranteed that T is a subsequence of S.
inputFormat
The input consists of exactly two lines:
- The first line contains the string S.
- The second line contains the string T.
Both strings consist of lowercase and/or uppercase English letters.
outputFormat
Output a single integer, which is the minimum number of deletions required from S so that T remains as a subsequence of the resulting string.
## sampleabcabc
aabb
2