FastPrepMost-Likely Next-Word Continuation Predictor
Problems/Most-Likely Next-Word Continuation Predictor

Most-Likely Next-Word Continuation Predictor

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source gives training sentences already split into words, examples of the most likely next word, follow-ups about memory and data structures, and completing a whole sentence. We define how often a word follows another, how ties break, what to do when no word follows, a limit on the completion, and the data size. Our version is about 92% the same as the reported question.

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 trainingData is at most 100000.
  • 1 <= queries.length <= 10000.
  • 1 <= maxWords <= 100.
  • Every token and query is a nonempty case-sensitive string of at most 40 characters.
  • 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

Interview reports that mention this question

  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
  • Bloomberg New Grad Screens: 30 Experiences (Part 4 of 5)

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)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public String[][] predictContinuations(String[][] trainingData, String[] queries, int maxWords) {
        // Write your code here.
    }

}
Checking account…