Document Store with Predicates

Asked at SnowflakePhone screen

Reported by the problem's creator, not verified

Documents are identified by a file name and hold text made of whitespace-separated words. Word matching is exact and case-sensitive: a predicate word matches a document only if the document contains that exact word.

A predicate is built from words, &&, || and parentheses. && binds tighter than ||. Predicates are always valid, and operators and parentheses may or may not be surrounded by spaces.

Each test drives one DocStore through a sequence of calls and checks every return value.

Examples

  1. Example 1

    Input: init = [["n1","n2","n3"],4,2], operations = [["insert_doc",["doc1","a b"]],["check_contains",["doc1","a && b || c"]],["check_contains",["doc1","c || a && c"]],["check_contains",["doc1","a || b && c"]],["check_contains",["doc1","(a || c) && (c || b)"]],["check_contains",["doc1","(a && c)||b"]],["check_contains",["nodoc","a || b"]],["check_contains",["doc1","a&&c"]]]

    Output: [null,true,false,true,true,true,false,false]

    Explanation: doc1 holds the words a and b. a && b || c reads as (a && b) || c, which is true. c || a && c reads as c || (a && c), which is false. a || b && c reads as a || (b && c), which is true. The parenthesized forms and the space-free a&&c parse the same way. The missing file nodoc has no words, so a || b is false.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.