Problem · String
Validate a Single-Letter Word Sequence
Learn this problemProblem statement
Given an array of strings words, determine whether it forms a valid single-letter word sequence.
The sequence is valid when every adjacent pair has the same length and differs at exactly one character position. A sequence with fewer than two words is valid.
A word may appear again later in the sequence, as long as each adjacent transition still changes exactly one character.
Function
isValidWordSequence(words: String[]) → booleanExamples
Example 1
words = ["hot","dot","cog"]return = falsehot to dot changes one position, but dot to cog changes two.
Example 2
words = ["hot","dot","dot"]return = falseThe final transition changes zero positions, but every adjacent pair must change exactly one.
Example 3
words = ["hot","dot","dog"]return = trueEach adjacent pair has length three and changes exactly one character.
Constraints
0 <= words.length <= 100000.- Every word contains only lowercase English letters.
- The total number of characters across all words is at most
200000.