Problem · Array
Match Consecutive Word Boundaries
Learn this problemProblem statement
Given an array of strings words, check each consecutive pair of words to determine whether they start and end with the same character.
Return a boolean array of length words.length - 1, where the ith element is true if words[i] and words[i + 1] start with the same character and end with the same character, and false otherwise.
A solution with time complexity no worse than O(words.length * sum(words[i].length)) will fit within the execution time limit.
Function
matchConsecutiveWordBoundaries(words: String[]) → boolean[]Examples
Example 1
words = ["abcd","abdd","da","dd"]return = [true,false,false]- The first character of both
words[0]andwords[1]isa, and their last character isd, so the zeroth element of the answer istrue. - The first character of
words[1]isa, but the first character ofwords[2]isd, so the first element of the answer isfalse. - The last character of
words[2]isa, but the last character ofwords[3]isd, so the second element of the answer isfalse.
Example 2
words = ["a","a"]return = [true]Both words start and end with a, so the only element of the answer is true.
Constraints
1 <= words.length <= 1001 <= words[i].length <= 100- Every word contains only lowercase English letters.