Most-Frequent Next-Word Predictor
Updated
Problem statement
Train a next-word predictor from one ordered array of case-sensitive tokens. Every adjacent pair contributes one observation from its first token to its second.
For each query token, return the observed following token with highest frequency. Break frequency ties by lexicographically smaller token. Return the empty string when the query has no observed successor. Precompute the winning successor while processing the training data so each query is answered in average O(1) time.
Function
predictNextWords(trainingTokens: String[], queries: String[]) → String[]Examples
Example 1
trainingTokens = ["i","like","tea","i","like","coffee","i","like","tea"]queries = ["i","like"]return = ["like","tea"]The word after i is always like, while tea follows like twice and coffee once.
Example 2
trainingTokens = ["x","z","x","a"]queries = ["x"]return = ["a"]The successors a and z tie, so the lexicographically smaller a wins.
Constraints
1 <= trainingTokens.length, queries.length <= 200000- Every token is a nonempty printable ASCII string of length at most
40. - The total number of token characters across both arrays is at most
1000000.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
- Design a Food Rating SystemApple · PHONE SCREENApple interview questions
- Hierarchical In-Memory File SystemClay · PHONE SCREEN
- Design File SystemGoogle · PHONE SCREENGoogle interview questions
- Numeric Poker OperationsRippling · PHONE SCREENRippling interview questions
- Implement uniq: Unique LinesVanta · ONSITE INTERVIEW
- Reference-Counted Deduplicating File SystemCitadel · PHONE SCREENCitadel interview questions
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)