Given a text corpus, clean it and implement logic to predict the most probable next word
Asked in the onsite_round_3 stage. NLP-focused technical round.
Implement predict_next_word(corpus, current_word). Convert corpus text to lowercase alphanumeric tokens, removing punctuation. Count each word that immediately follows current_word. Return the most frequent successor, breaking ties by lexicographically smaller word. Return None if the cleaned query is absent or has no successor.
Signature: def predict_next_word(corpus, current_word):
Example: "Apple builds great products. Apple builds secure products.", "apple" returns "builds". For "builds", both great and secure occur once, so return "great".
None when no successor is observeddef predict_next_word(corpus, current_word):