Prefix Matcher

Asked at Datadog

Reported by the problem's creator, not verified

Import another question

Implement the class PrefixMatcher. add(prefix) stores a prefix, and match(strings) reports which of the given strings begin with at least one stored prefix.

Examples

  1. Example 1

    Input: init = [], operations = [["add",["ab"]],["add",["xyz"]],["match",[["abc","xy","xyzzy","ba","ab"]]]]

    Output: [null,null,["abc","xyzzy","ab"]]

    Explanation: abc and ab begin with ab, and xyzzy begins with xyz. xy is shorter than xyz, so it does not match, and ba does not begin with ab.

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.