Two pages have URL slugs a and b that are supposed to be the same. To find how far apart they are, you may only delete characters, from either slug, one at a time.
Write fewestDeletions(a, b) that returns the fewest deletions needed to make the two slugs equal.
Input: a = "card", b = "cart" Output: 2
Delete d from card and t from cart; both become car.
Input: a = "menu", b = "menu" Output: 0
They already match.
1 <= a.length, b.length <= 500-.Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #531 Fewest Deletions to Match Two Slugs. 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.