← Back to challenges

Word Chain 2.0

PythonHardarraysstringsvalidation

Instructions

Let's update our previous word-chain definition. In this 2.0 version, a word-chain is an array of words, where the next word is formed by either:

  1. Changing exactly one letter from the previous word
  2. Adding or subtracting one letter

Note: You can only do one (not both) for each word change.

Examples

isWordChain(["row", "crow", "crown", "brown", "brawn"]) ➞ True
# add "c" to "row" to get "crow", "n" to get "crown", etc.

isWordChain(["flew", "flaw", "flan", "flat", "fat", "rat", "rot", "tot"]) ➞ True

isWordChain(["meek", "meet", "meat", "teal"]) ➞ False
# "meat" => "teal" changes 2 letters (can only change 1)

isWordChain(["run", "runny", "bunny"]) ➞ False
# "run" => "runny" adds 2 letters (can only add 1)

Notes

  • All words will be in lower-case.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.