Practice Minimum Cost to Convert String II
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Minimum Cost to Convert String II
Problem Statement
source and target have the same length. Rule i replaces a substring equal to original[i] by changed[i] at cost[i]. You may apply rules repeatedly, but any two operation intervals must be identical or disjoint; partial overlap is forbidden. Thus multiple replacements may chain over the same interval. Return the minimum total cost to obtain target, or -1 if impossible. Duplicate rules may occur.
Source: Minimum Cost to Convert String II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
source = "abcd", target = "acbe", original = ["a","b","c","c","e","d"], changed = ["b","c","b","e","b","e"], cost = [2,5,5,1,2,20]
28
# Example 2
source = "abcdefgh", target = "acdeeghh", original = ["bcd","fgh","thh"], changed = ["cde","thh","ghh"], cost = [1,3,5]
9
# Example 3
source = "abcdefgh", target = "addddddd", original = ["bcd","defgh"], changed = ["ddd","ddddd"], cost = [100,1578]
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Cost to Convert String II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.