Most-Likely Next-Word Continuation Predictor
Updated
Problem statement
Train a word-transition predictor from trainingData. Every adjacent pair (word, nextWord) in a training sequence contributes one occurrence to that transition.
For each word, its predicted successor is the outgoing word with the greatest transition count. Break equal-count ties by lexicographically smaller successor.
For each word in queries, construct a continuation by repeatedly appending its predicted successor and using that successor as the next current word. Stop after maxWords appended words or as soon as the current word has no learned successor. Return one continuation row per query.
Function
predictContinuations(trainingData: String[][], queries: String[], maxWords: int) → String[][]Examples
Example 1
trainingData = [["I","am","sam"],["am","sam"]]queries = ["I","am"]maxWords = 3return = [["am","sam"],["sam"]]I transitions to am, then am transitions to sam. No successor was learned for sam.
Example 2
trainingData = [["a","b"],["a","c"],["a","b"],["b","d"]]queries = ["a","missing"]maxWords = 2return = [["b","d"],[]]The transition a → b appears twice while a → c appears once. The unseen query has no continuation.
Example 3
trainingData = [["x","z"],["x","y"],["y","x"]]queries = ["x"]maxWords = 4return = [["y","x","y","x"]]x → y wins the equal-frequency tie over x → z. The learned cycle is bounded by maxWords.
Constraints
- The total number of words across
trainingDatais at most100000. 1 <= queries.length <= 10000.1 <= maxWords <= 100.- Every token and query is a nonempty case-sensitive string of at most
40characters. - A training sequence may contain one word and therefore contribute no transition.
More Bloomberg LP Onsite Interview questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Highest Bid Campaign MatcherStackAdapt · ONSITE INTERVIEWStackAdapt interview questions
- 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