Average Color Segments in Random Squares

Expected segments in colored squares row is a medium quant interview question on Expected Value, reported to have been seen at Akuna Capital, Goldman Sachs and Squarepoint Capital.

Difficulty Medium Topic Expected Value Reported at Akuna Capital, Goldman Sachs, Squarepoint Capital

MyQuantPartner is not affiliated with, endorsed by, or sponsored by these companies, and all trademarks belong to their respective owners.

This random-coloring problem is about how often a sequence breaks into homogeneous stretches when each position is independently assigned one of two values. It lives at the intersection of discrete probability, combinatorics, and expected value, and it's a classic example of runs in a random binary string, frequently seen in quant prep for interviews and tests. This kind of structure is popular in quant interviews because it is simple to state yet mathematically rich.

It trains your ability to formalize random patterns using indicator variables, compute expectations in a clean way, and connect local randomness to global structure. You practice translating an intuitive notion of "segments" into a precise probabilistic quantity and using independence and symmetry to simplify the analysis.

This matters in quant interviews because many market and trading problems involve sequences of states, regime switches, and clustering of events. Interviewers want to see if you can quickly model such situations, identify relevant random variables, and compute expectations without brute-force enumeration, all core skills for quantitative finance roles.

What it tests

Whenever a sequence is randomly partitioned into runs based on a binary (or more generally, categorical) attribute, the expected number of runs (connected components) is determined by the expected number of transitions between different values, plus one for the initial segment. This is because a new component starts exactly when the attribute changes from one value to another as you move through the sequence. The independence and uniformity of the coloring ensure that each pair of adjacent elements has a fixed probability of differing, making the expected number of transitions easy to compute. The linearity of expectation allows us to sum these probabilities over all adjacent pairs, regardless of dependencies among the indicator variables. This principle holds for any sequence where each element is independently assigned a value from a finite set, and components are defined by maximal stretches of identical values.

Practise this question with written feedback, or hear it in a spoken mock interview.

Get started free