FastPrepValidate a Single-Letter Word Sequence
Problem · String

Validate a Single-Letter Word Sequence

Learn this problem
EasyReddit logoRedditFULLTIMEPHONE SCREEN

Problem 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[]) → boolean

Examples

Example 1

words = ["hot","dot","cog"]return = false

hot to dot changes one position, but dot to cog changes two.

Example 2

words = ["hot","dot","dot"]return = false

The final transition changes zero positions, but every adjacent pair must change exactly one.

Example 3

words = ["hot","dot","dog"]return = true

Each 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.

More Reddit problems

drafts saved locally
public boolean isValidWordSequence(String[] words) {
    // Write your solution here.
}
words["hot","dot","cog"]
expectedfalse
checking account