FastPrepMarkov Transition Counts and Probabilities
Problems/Markov Transition Counts and Probabilities

Markov Transition Counts and Probabilities

Retool logoRetool● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Retool onsite report from March 24, 2026 asks you to count the tokens that follow each token, and then return the Markov transition probabilities. We chose string rows in a set form, so both results are exact and repeatable. Our version is about 92% the same as the reported question.

Given an observed token sequence, count every adjacent transition from a current token to its next token.

Return one row for each observed transition in the exact form current->next:count/total, where total is the number of outgoing transitions observed from current. The fraction is intentionally not reduced. Sort rows first by current, then by next.

Function

markovTransitionStats(tokens: String[]) → String[]

Examples

Example 1

tokens = ["a","b","a","c","a","b"]return = ["a->b:2/3","a->c:1/3","b->a:1/1","c->a:1/1"]

The three outgoing transitions from a go to b twice and c once.

Example 2

tokens = ["x","x","x"]return = ["x->x:2/2"]

Both adjacent pairs are self-transitions.

Example 3

tokens = ["z","a"]return = ["z->a:1/1"]

One pair creates one certain transition.

Constraints

  • 2 <= tokens.length <= 200000.
  • Each token has 1 to 30 lowercase English letters.

More Retool interview questions

  • Maximum Profit with Exactly One Stock TransactionPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Execute In-Memory SQL QueriesPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2026
  • Maximum Profit with Exactly Two Stock TransactionsPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2026
  • Next Consistent Wordle GuessPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2024
  • Wordle FeedbackPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2024
  • Order Sources by Their DependenciesPHONE SCREEN · Seen Oct 2026
  • Wordle Guess LoopPHONE SCREEN · Seen Jun 2024

Similar questions at other companies

  • Deduplicated Query RegistrationDatadog · ONSITE INTERVIEWDatadog interview questions
  • Dictionary Words Formable From LettersGoogle · ONSITE INTERVIEWGoogle interview questions
  • Apply Operations to Make a String EmptyFlexport · PHONE SCREENFlexport interview questions
  • Count One-Swap Number PairsCapital One · OACapital One interview questions
  • How Many Sentences?Chubb · OAChubb interview questions
  • Perfect SubstringsVisa · OAVisa interview questions
  • Cheating CodemakerJane Street · OAJane Street interview questions
  • AI Role: Next-Word Prediction from a Cleaned CorpusApple · PHONE SCREENApple interview questions
  • Count Equal-Frequency SubsequencesExpedia · OAExpedia interview questions
  • How Many Sentences?Atlassian · OAAtlassian interview questions
All Retool interview questionsSee Retool hiring insights
Saved
class Solution {
    public String[] markovTransitionStats(String[] tokens) {
        // write your code here
    }
}
Checking account…