← Back to challenges

Word Chain

PythonHardarraysstringsvalidation

Instructions

A word-chain is an array of words, where the next word is formed by changing exactly one letter from the previous word. We do not add or subtract letters from words, only change them.

Create a function that returns True if an array is a word-chain and False otherwise.

Examples

is_word_chain(["meal", "seal", "seat", "beat", "beet"]) ➞ True
# Change "m" in "meal" to get "seal", "l" to get "seat", etc.

is_word_chain(["red", "bed", "bet", "bat", "sat"]) ➞ True

is_word_chain(["red", "bat", "cat", "sat"]) ➞ False
# Do not change more than one letter ("red" and "bat").

is_word_chain(["read", "red", "led", "lad", "lady"]) ➞ False
# Do not add or subtract letters.

Notes

  • Each word in a word chain has equal length.
  • All words will be in lower case.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.