Minimum Insertions / Deletions to Convert String
Implement minOperations
Given two strings `s1` and `s2`, find the minimum combined number of character insertions into `s1` and deletions from `s1` needed to turn `s1` into `s2`.
The characters that make up the longest common subsequence of `s1` and `s2` never need to be touched — they're already sitting in the right relative order in both strings, so they can act as a fixed skeleton. Everything else has to change: a character of `s1` that isn't part of that shared skeleton has no partner in `s2` and must be deleted, and a character of `s2` that isn't part of it has no partner in `s1` yet and must be inserted. That turns the whole problem into computing one number — the length of the longest common subsequence — and plugging it into a simple formula.
Example 1:
Input: s1 = "heap", s2 = "pea"
Output: 3
Example 2:
Input: s1 = "abc", s2 = "abc"
Output: 0
Example 3:
Input: s1 = "abc", s2 = "def"
Output: 6
+ 7 hidden test cases run on Submit.
Constraints:
- ●
0 ≤ s1.length, s2.length ≤ 12 - ●
s1 and s2 consist of lowercase English letters
s1 =
heap
s2 =
pea