A design system is renaming a CSS class from begin to end, but a strict linter only lets each commit change exactly one letter, and every intermediate name must be one of the approved names in allowed. The final name end must also be approved.
Write renameSteps(begin, end, allowed) that returns the fewest commits needed, or -1 if it can't be done. If begin === end, the answer is 0. All names are lowercase letters a to z and have the same length. begin itself doesn't need to be approved.
Input: begin = "tabs", end = "tips", allowed = ["tibs","tips","taps","tops"] Output: 2
For example tabs → taps → tips: two commits, each changing one letter.
Input: begin = "link", end = "line", allowed = ["lint","lone"] Output: -1
line isn't an approved name, so it can never be the final name.
1 <= begin.length <= 100 <= allowed.length <= 5000Run 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 #434 Rename a CSS Class One Letter at a Time. 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.