Back to problems

Next-Word Predictor

Algorithm · Google · Medium

Most Frequent Successor Medium · Hash Table, Design, Counting · Company Tags · Hints Design a data structure that processes sentences one by one, learns word-follow patterns, and then supports instant queries for the most likely next word. Implement two operations: train(sentence) accepts a non‑empty string of space‑separated words. For each adjacent pair (prev, next) inside the sentence, increase the recorded frequency of next following prev. Immediately after incrementing…

Checking your access…