Build an inverted index over a list of documents and support single-word and phrase search (documents containing the words at consecutive positions).
Asked in the onsite coding stage. Candidate's Java solution shown.
Implement search_documents(documents, queries). documents is a list of strings, and queries is a list of non-empty strings. Tokenize by whitespace and compare case-insensitively. Return one sorted list of zero-based document indices per query. A phrase matches only when its words occur consecutively in the same order.
def search_documents(documents, queries):