words and a dictionary vocab. Every word in both lists is made of lowercase English letters, and all of them have the same length.
One edit replaces a single letter of a word with any other letter. A word from words is accepted if at most two edits turn it into some word of vocab (zero edits count too).
Return all accepted words in the order they appear in words.words=["cart", "milk", "bred", "jamm"], vocab=["card", "brew", "silk"] → ['cart', 'milk', 'bred']
cart → card and bred → brew take one change each, and so does milk → silk. But jamm differs from every vocabulary word in at least three positions.
words=["abc"], vocab=["xyz"] → []
All three letters differ, so two changes are not enough.
words=["moon", "moon"], vocab=["noon"] → ['moon', 'moon']
Repeated words stay in the answer: each occurrence is checked on its own.
words=["cart", "milk", "bred", "jamm"], vocab=["card", "brew", "silk"]
['cart', 'milk', 'bred']
Run checks the first 3 tests in your browser. Submit checks all 76 tests on the server, hidden ones included.