Next Word Predictor
Asked at Google
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
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,
gois followed bylefttwice andrightonce, sopredict(go)isleft. Bothleftandrightare followed bygoonce. The lasttraincall raisesrightto 2, tying withleft;leftfollowedgofirst, sopredict(go)staysleft. A word never seen as a predecessor, likestop, givesNone.