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

Markov Transition Counts and Probabilities

Retool logoRetool● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Retool onsite report from March 24, 2026 asks candidates to count each token's next tokens and then return the associated Markov transition probabilities. The canonical string rows make both requested results exact and deterministic. The judged contract matches the visible source at about 92%.

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 problems

  • Maximum Profit with Exactly One Stock TransactionPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Order Sources by Their DependenciesPHONE SCREEN · Seen Oct 2026
  • Execute In-Memory SQL QueriesPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2026
All Retool interview questionsSee Retool hiring insights
Saved
public String[] markovTransitionStats(String[] tokens) {
    // write your code here
}
Checking account…