Next Word Predictor

Asked at GoogleOnsite

Reported by the problem's creator, not verified

Each test creates one Predictor instance and calls its methods in order. The output lists every method call's return value; calls that return None record null.

Examples

  1. Example 1

    Input: init = [], operations = [["train",[["go","left","go","right","go","left"]]],["predict",["go"]],["predict",["left"]],["predict",["right"]],["predict",["stop"]],["train",[["go","right"]]],["predict",["go"]]]

    Output: [null,"left","go","go",null,null,"left"]

    Explanation: After the first sequence, go is followed by left twice and right once, so predict(go) is left. Both left and right are followed by go once. The last train call raises right to 2, tying with left; left followed go first, so predict(go) stays left. A word never seen as a predecessor, like stop, gives None.

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.