A form shows a gentle "did you mean" hint only when the typed value is very close to a saved value. Close means the two strings are equal, or one insert, one delete, or one replaced character turns one into the other.
Write isOneEditAway(typed, saved) that returns true if the strings are at most one edit apart, and false otherwise.
Input: typed = "modal", saved = "model" Output: true
Replace a with e.
Input: typed = "tab", saved = "tables" Output: false
The lengths differ by 3, so at least 3 inserts are needed.
0 <= typed.length, saved.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 #537 One Keystroke Away. 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.