Minimum Steps to Convert String with Operations
You are given two strings, word1 and word2, of equal length.
You are given two strings, word1 and word2, of equal length. You need to transform word1 into word2.
For this, divide word1 into one or more contiguous substrings. For each substring substr you can perform the following operations:
Each of these counts as one operation and each character of each substring can be used in each type of operation at most once (i.e. no single index may be involved in more than one replace, one swap, or one reverse).
Return the minimum number of operations required to transform word1 into word2.
Example 1
Input: word1 = "abcdf", word2 = "dacbe"
Output: 4
Explanation: Divide word1 into "ab" , "c" , and "df" . The operations are:
Example 2
Input: word1 = "abceded", word2 = "baecfef"
Output: 4
Explanation: Divide word1 into "ab" , "ce" , and "ded" . The operations are:
Example 3
Input: word1 = "abcdef", word2 = "fedabc"
Output: 2
Explanation: Divide word1 into "abcdef" . The operations are:
Constraints
- 1 <= word1.length == word2.length <= 100
- word1 and word2 consist only of lowercase English letters.
Hints
Companies
No companies reported yet.
Discussion
Sign in to join the discussion.
Loading discussion...
Test results
No test cases yet.