A command-line tool in the browser shows "did you mean" when you mistype a command. It compares the typed text with every known command in commands and suggests the one with the smallest edit distance (inserts, deletes, and replacements of single characters).
Write closestCommand(typed, commands) that returns that command. If several commands are equally close, return the one that appears first in commands.
Input: typed = "brnch", commands = ["branch","bench","patch"] Output: "branch"
branch (insert a) and bench (replace r with e) are both 1 edit away, and branch comes first.
Input: typed = "comit", commands = ["clone","commit","config"] Output: "commit"
Inserting one m gives commit; the others need more edits.
1 <= commands.length <= 1001 <= typed.length, commands[i].length <= 30-.Run 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 #538 Closest Command Suggestion. 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.