A text-sync tool makes two strings equal by deleting characters from either one. Deleting a character costs its character code, char.charCodeAt(0), so deleting "a" costs 97.
Write cheapestDeletions(a, b) that returns the smallest total cost of deletions that make a and b equal.
Input: a = "ab", b = "ba" Output: 194
Delete a from both to keep b: 97 + 97 = 194. Keeping a instead costs 98 + 98.
Input: a = "abc", b = "abc" Output: 0
They already match.
1 <= a.length, b.length <= 1000Run 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 #532 Cheapest Deletions by Character Code. 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.