FastPrepMatch Consecutive Word Boundaries
Problem · Array

Match Consecutive Word Boundaries

Learn this problem
EasyCapital One logoCapital OneINTERNOA

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

More Capital One problems

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