Problem · Array

Match Consecutive Word Boundaries (for mle also :)

Learn this problem
EasyByteDance logoByteDanceINTERNNEW GRADOA

Problem 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] and words[1] is a, and their last character is d, so the zeroth element of the answer is true.
  • The first character of words[1] is a, but the first character of words[2] is d, so the first element of the answer is false.
  • The last character of words[2] is a, but the last character of words[3] is d, so the second element of the answer is false.

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
  • 1 <= words[i].length
  • Every word contains only lowercase English letters.

More ByteDance problems

drafts saved locally
public boolean[] matchConsecutiveWordBoundaries(String[] words) {
    // write your code here
}
words["abcd","abdd","da","dd"]
expected[true,false,false]
checking account