← 返回 netflix 的题目列表Inverted Index with Phrase Search
类型:online_judge
Given a list of documents (each document is a whitespace-separated text), build an inverted index and support search.
Input
documents: List<String> (document id is its index in the list)
phrase: String containing one or more space-separated words
Output
Return a list of matching original document strings (any order)
Matching rules
If phrase has one word: return all documents containing that word.
If phrase has multiple words: return documents containing the phrase with words appearing in order and in consecutive positions.
Case-insensitive matching.
Constraints
D <= 1e4, L <= 1e3, Q <= 20
Example
Docs:
"the quick brown fox"
"the slow brown cow"
"to be or not to be that is the question"
"bar foo bar barfoo" Queries:
"brown" -> docs 1,2
"slow brown" -> doc 2
"the cow" -> doc 2
"bar bar" -> doc 4
Example
Input
documents=[the quick brown fox; the slow brown cow; to be or not to be that is the question; bar foo bar barfoo]
query=brown
Output
[the quick brown fox, the slow brown cow]