A collaborative editor charges different costs for different kinds of change when it measures how much a document title was edited. Inserting a character costs insertCost, deleting one costs deleteCost, and replacing one character with another costs replaceCost.
Write weightedEditCost(a, b, insertCost, deleteCost, replaceCost) that returns the smallest total cost to turn a into b.
Input: a = "cat", b = "cut", insertCost = 1, deleteCost = 1, replaceCost = 5 Output: 2
Replacing a costs 5, but deleting a (1) and inserting u (1) costs 2.
Input: a = "", b = "abc", insertCost = 2, deleteCost = 1, replaceCost = 1 Output: 6
Three inserts at 2 each.
0 <= a.length, b.length <= 5001 <= insertCost, deleteCost, replaceCost <= 100Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #539 Weighted Edit Cost. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.