FastPrepWord Search Across Documents
Problem · Array

Word Search Across Documents

Learn this problem
EasyConfluent logoConfluentFULLTIMEONSITE INTERVIEW

Problem statement

Given an array of text documents and a query word, return the zero-based indices of all documents that contain the query as a complete word.

Words are lowercase English-letter tokens separated by one space. Matching is exact: a query does not match part of a longer token. Include each matching document index once, in increasing order.

Function

findDocumentsWithWord(documents: String[], word: String) → int[]

Examples

Example 1

documents = ["red blue green","bluebird flies","green blue"]word = "blue"return = [0,2]

Documents 0 and 2 contain token blue. Token bluebird is not an exact match.

Example 2

documents = ["alpha beta","gamma delta","alpha"]word = "omega"return = []

No document contains the token omega.

Constraints

  • 1 <= documents.length <= 1000.
  • 1 <= documents[i].length <= 1000.
  • 1 <= word.length <= 50.
  • Every document contains lowercase English words separated by exactly one space, with no leading or trailing space.
  • word contains only lowercase English letters.

More Confluent problems

drafts saved locally
public int[] findDocumentsWithWord(String[] documents, String word) {
    // write your code here
}
documents["red blue green","bluebird flies","green blue"]
word"blue"
expected[0,2]
checking account