Quant puzzles, solved step by step
- Puzzles
- 100
- Traced to a firm
- 71
- Topics
- 12
- Hard
- 30
051You and a friend agree to meet at a spot some time between 5 and 6 pm. Each of you arrives at an independent, uniformly random time in that hour and waits 20 minutes for the other before leaving (or until 6 pm, whichever comes first). What is the probability you meet?Jane StreetNew York · 2026
Try it first
Before you draw anything: what is the chance you meet?
Show the worked solution
5/9, about 55.6%. Put your arrival time on one axis and your friend's on the other, so every outcome is a point in a unit square. You meet when the two times differ by at most a third of an hour, a band along the diagonal. The two corner triangles outside the band each have legs of 2/3, area 2/9, so the band is 1 - 4/9 = 5/9.
Why turn two arrival times into a square?
Think of two people trying to catch each other at a tea stall with no phones. Nothing about the answer depends on who is you and who is the friend; it depends only on the pair of times. With two independent uniform times, every pair is equally likely, so the pair is a point spread evenly over a square and any probability is simply an area. The event you meet becomes a region: the set of points where the two times are within 20 minutes of each other. That region is a diagonal band, because the line x = y is where you arrive together.
Plotting your arrival against your friend's, the meeting region is the diagonal band where the times differ by 20 minutes or less; the two white corner triangles, each 2/9 of the square, are the misses, so you meet with probability 5/9. How do you get the area without any integration?
Count the region you do not want. The two corners where one person arrives more than 20 minutes after the other are right triangles with both legs 40 minutes long, which is 2/3 of the side. Each has area (2/3) x (2/3) / 2 = 2/9, together 4/9, so the band is 5/9. Complements are the fastest route here, as they are for most geometric probability questions, because the leftover pieces are usually triangles.
The relationshipX, Y the two arrival times as fractions of the hour, independent and uniform on 0 to 1 w the waiting time as a fraction of the hour, here 20 of 60 minutes What it says in wordsThe chance of meeting is one minus the two corner triangles, whose legs are each one minus the waiting time.What does the general formula tell you that the number does not?
Read 2w - w squared term by term. The 2w is the naive answer of either person waiting, and the minus w squared removes the double count and the clipping at the edges of the hour. It also tells you how waiting time buys certainty: to meet half the time each person must wait about 17.6 minutes, and to be sure each must wait the whole hour. The same picture prices any tolerance between two random arrivals, such as two orders landing in the same matching window of an auction.
Where candidates lose it
The common answer is 1/3, from reading 20 minutes as a third of the hour. It ignores that either person can be the one who waits, and it has no way to handle the edges of the hour, where a person arriving at 5:55 can only wait five minutes.
The second trap is trying to integrate over one person's arrival time case by case near the edges. It works but wastes three minutes. Draw the square first and subtract the two triangles out loud.
What the interviewer asks next
- How long would each person need to wait for a 50% chance of meeting?
- You wait 10 minutes and your friend waits 30. What is the chance now?
- Three people arrive at random in the hour and each waits 20 minutes. What is the chance all three are together at some moment?
Asked at Jane Street, Technology, New York, 2026 (Wall Street Oasis):
1v1 math problems. bus stop. two people meeting probelm
052You roll a fair die repeatedly until the first six appears. What is the expected sum of all the rolls before the six, not counting the six itself?Quant tradingProp trading firms
Try it first
Pick your answer before working it.
Show the worked solution
15. The first six takes 6 rolls on average, so 5 rolls come before it. Each of those rolls is known not to be a six, so it is uniform on 1 to 5 and averages 3. Expected count times expected size gives 5 x 3 = 15. The check: all rolls including the six average 6 x 3.5 = 21, and taking off the final six leaves 15.
How many rolls come before the six?
Picture waiting at a stop where each minute a bus arrives with chance 1 in 6. On average you wait 6 minutes, and the sixth is the one where it comes. The number of rolls up to and including the first six is geometric with mean 1/p = 6, so the number strictly before it is 5. That is the first factor. Most candidates get this far; the loss comes in the second factor.
A typical game has five non-six rolls before the stopping six, and each of those rolls averages 3 because it is known not to be a six, so the expected sum is 5 x 3 = 15; the full-sum check of 6 x 3.5 less the final 6 also gives 15. Why is each of those rolls worth 3 and not 3.5?
Because you are told something about them. Every roll before the stopping six is, by definition, not a six, so its distribution is the die conditioned on 1 to 5, which averages exactly 3. Using 3.5 gives 17.5, the most common wrong answer. It is the same slip as averaging the income of people who did not win a prize with everyone's income, prize winners included.
The relationshipN the number of rolls before the first six, mean 5 X | X not 6 a roll known not to be a six, uniform on 1 to 5 E the expected sum from any fresh start What it says in wordsExpected count times the expected size of each piece gives 15, and the one-step recursion confirms it.How do you check 15 a second way in the room?
Two checks, both fast. The recursion: with chance 5/6 the next roll is not a six, adds 3 on average and you are back where you started, so E = (5/6)(3 + E), which solves to 15. The full sum: Wald's identityFor a stopping time N that does not look into the future, the expected sum of N independent identical draws equals E[N] times the mean of one draw. applied to every roll including the six gives 6 x 3.5 = 21, and the last roll is always exactly 6, so the rest must average 15. Say both; the second one shows you understand why the conditional mean is 3.
Where candidates lose it
The trap is 17.5: the right count, 5, multiplied by the unconditional mean of a die. The interviewer set the question up so that the rolls you sum are selected, not random, and wants to see whether you notice.
The second trap is multiplying 6 rolls by 3.5 and stopping at 21, which includes the six the question told you to exclude. Say what is counted before you multiply.
What the interviewer asks next
- What is the expected sum if you do count the six?
- What is the expected sum of the rolls before the first time you roll a 1 or a 2?
- What is the expected number of rolls until two sixes in a row?
053Five assets each have unit variance, and every pair has correlation 0.4. What are the eigenvalues of the correlation matrix, and what share of total variance does the first principal component explain?Jump TradingPudong Xinqu · 2023
Try it first
Before any algebra: what share of variance does the first component explain?
Show the worked solution
One eigenvalue of 2.6 and four of 0.6, so the first principal component explains 52%. Write the matrix as 0.6 times the identity plus 0.4 times a matrix of ones. The all-ones vector is an eigenvector with eigenvalue 0.6 + 5 x 0.4 = 2.6; any vector whose weights sum to zero is killed by the ones matrix and has eigenvalue 0.6. The trace check: 2.6 + 4 x 0.6 = 5.
What structure should you spot before touching a determinant?
Think of five students whose marks all move together when the paper is hard, plus their own good and bad days. There is one shared shock and five private ones. An equicorrelation matrix is exactly that: R = (1 - rho) I + rho J, where J is the matrix of all ones, so its eigenvectors are those of J and you never need a characteristic polynomial. J sends the all-ones vector to 5 times itself and sends any vector whose entries sum to zero to zero. Those two facts give every eigenvalue.
The 5 by 5 matrix with 0.4 off the diagonal has one eigenvalue of 2.6, carried by the equal weight portfolio and explaining 52% of the variance, and four eigenvalues of 0.6, carried by long short combinations and explaining 12% each. How do the eigenvalues fall out, and how do you check them?
Apply R to the all-ones vector: each row sums to 1 + 4 x 0.4, so the equal weight portfolio has eigenvalue 1 + (n - 1) rho = 2.6. Apply R to any vector with weights summing to zero, such as long asset 1 and short asset 2: the rho J part vanishes and only (1 - rho) = 0.6 is left, and there are four independent such vectors. The eigenvalues must add to the trace, the sum of the diagonal, which is 5: 2.6 + 2.4 = 5.
The relationshiprho the common pairwise correlation, 0.4 n the number of assets, 5 1 1^T the all-ones matrix J What it says in wordsA common correlation creates one large factor for the average and leaves every long short combination with the same small variance.What does the answer say about a real portfolio?
The first component is the market: equal weights, and its share rises towards rho as you add assets. With 50 assets at the same correlation the first eigenvalue is 1 + 49 x 0.4 = 20.6, 41.2% of the total, while each of the other 49 stays at 0.6. Diversification removes the private shocks but never the common one. The same formula gives a limit: the smallest eigenvalue 1 - rho is always fine, but 1 + (n - 1) rho must stay positive, so five assets cannot all share a correlation below -0.25.
Where candidates lose it
The loss is trying to expand a 5 by 5 determinant by hand. It is slow, error prone and signals that you did not see the structure. The interviewer is waiting for identity plus ones matrix.
The second trap is reading 40% as the explained share because the correlation is 0.4. The share is (1 + (n - 1) rho)/n, which is 52% here and only approaches rho as n grows.
What the interviewer asks next
- What is the most negative common correlation five assets can have?
- What are the eigenvectors of the four 0.6 eigenvalues, and why are they not unique?
- If one asset is removed, what share does the first component explain?
- How would you spot a second factor, such as a sector, in the eigenvalues?
Asked at Jump Trading, Prop Trading, Pudong Xinqu, 2023 (Wall Street Oasis):
Some very difficult linear algebra questions about PCA and eigenvalues
054With interest rate r and volatility sigma, check which of these satisfy the Black-Scholes equation: V = S, V = K e^(-r(T-t)), and V = S squared. Explain what the ones that pass are as trades, and fix the one that fails.Quant researchOptions market making
Try it first
Which candidates pass?
Show the worked solution
V = S and V = K e^(-r(T-t)) satisfy it; V = S squared does not. The first is the stock itself and the second is a zero-coupon bond paying K at T, both traded assets that must earn r. S squared has gamma 2 and leaves (r + sigma squared) S squared unbalanced. Multiplying by e^((r + sigma squared)(T-t)) fixes it, which is the price of a claim paying S squared at expiry.
What is the equation actually saying?
Think of a household budget rule that any fair arrangement must obey: over one day, what you hold must earn the same as the same money in a savings account, once the risk has been hedged away. The Black-Scholes equation says that for a delta-hedged position, time decay plus the gamma term plus the financing of the hedge equals r times the value. Written in {term('greeks', 'Theta is the change in value with time, delta with the stock price, and gamma is the change in delta with the stock price.')}, it is theta + half sigma squared S squared gamma + r S delta = r V. A candidate price passes only if its greeks balance that line.
The relationshipdV/dt theta, the change in value as time passes d2V/dS2 gamma, how fast delta changes dV/dS delta, the hedge ratio r the interest rate What it says in wordsA hedged position's decay, convexity and financing must add up to exactly the interest the money would earn.Substituting each candidate's theta, delta and gamma, the stock and the zero-coupon bond balance the equation exactly, S squared leaves a surplus of (r + sigma squared) S squared, and S squared times e^((r + sigma squared)(T - t)) balances it again. Why do the two that pass make sense as trades?
Anything that is itself a traded, self-financing asset must satisfy the equation, because the equation is only the statement that no hedged position earns more than r. V = S is just holding the stock: delta 1, no gamma, no decay, and the financing term rS matches rV. V = K e^(-r(T-t)) is a zero-coupon bond: it does not depend on S at all, and its value grows at exactly r as it approaches T. The stock and the bond are also the two pieces of the call price formula, which is why the check is worth a minute.
Why does S squared fail, and how do you repair it?
S squared has gamma 2, so the half sigma squared S squared gamma term adds sigma squared S squared, the delta term adds 2rS squared, and subtracting rV leaves (r + sigma squared) S squared with nothing to cancel it. A convex payoff gains from every move, so a fair price for it has to decay over time to pay for that gain, and S squared on its own has no decay. Try V = S squared times f(t): the equation forces f' = -(r + sigma squared) f, so the price of a claim paying S squared at T is S squared e^((r + sigma squared)(T - t)). At S = 100, r = 5%, sigma = 20% and one year, that is about 10,942, not 10,000, and the extra is the value of volatility.
Where candidates lose it
Candidates often say every function of S and t is a solution, or differentiate correctly and then fail to say what the passing solutions are. The question asks for the trades: the stock and a bond. Naming them turns a calculus check into finance.
The second trap is the sign of theta for the bond. Its value rises as t approaches T, so theta is +rV; getting that sign wrong makes the bond appear to fail.
What the interviewer asks next
- Which power of S, S to the a, satisfies the equation with no time factor?
- What is the price today of a claim paying log S at expiry?
- Why does the drift of the stock not appear anywhere in the equation?
055In how many ways can three positive integers, in order, sum to 10? To 11? Give the general formula for any total n of at least 3.Old Mission CapitalNew York · 2018
Try it first
How many ordered triples of positive integers sum to 10?
Show the worked solution
36 for 10, 45 for 11, and (n - 1)(n - 2)/2 in general. Write n as a row of n stars. Splitting it into three positive parts means placing two bars in two different gaps among the n - 1 gaps between stars. Each choice gives exactly one ordered triple, so the count is n - 1 choose 2: 9 choose 2 = 36 and 10 choose 2 = 45.
Why turn the sum into a row of stars?
Think of ten sweets in a line to be shared among three children in order, each getting at least one. You do not need to decide amounts; you only need to decide where to cut the line. Every ordered split of n into three positive parts is exactly one choice of two cut points among the n - 1 gaps between items, and every choice of two gaps gives a valid split. That one-to-one match is the whole argument, and it is what the interviewer wants to hear you state.
Ten stars have nine gaps between them; putting bars in two different gaps, here gaps 3 and 7, splits the stars into 3, 4 and 3, so the ordered triples summing to 10 number 9 choose 2, which is 36, and those summing to 11 number 45. What if the interviewer meant something slightly different?
Ask two quick questions before you answer: are zeros allowed, and does order matter. The word numbers hides three different questions, and each has a different count. If zeros are allowed, add one to each part first so they become positive and sum to n + 3: for 10 that is 12 choose 2 = 66. If order does not matter, the count for 10 drops to 8 unordered triples, and for 11 to 10, which you would list rather than compute. Asking which one is wanted takes five seconds and is part of the answer.
The relationshipn - 1 the number of gaps between n stars 2 the number of bars needed to make three parts What it says in wordsChoose two of the gaps between the stars; each choice is one ordered triple.How do you check 36 without the formula?
Fix the first number and count the rest. If the first part is a, the other two must sum to 10 - a, which can be done in 9 - a ordered ways. For a from 1 to 8 that is 8 + 7 + ... + 1 = 36. The counts for each total are the triangular numbers 1, 3, 6, 10 and so on, which is the same formula read another way.
Where candidates lose it
The fast wrong answer comes from listing unordered triples such as 1, 1, 8 and 2, 3, 5, getting 8, and not noticing the question counts order. The opposite slip is counting zeros and getting 66.
Both are avoided by one clarifying question at the start. Then give the stars and bars picture in a sentence, because the interviewer's next question is usually four or five parts.
What the interviewer asks next
- How many ways can four positive integers sum to 10?
- How many ordered triples of non-negative integers sum to 10?
- How many ordered triples of positive integers sum to 10 with every part at most 5?
Asked at Old Mission Capital, Finance, New York, 2018 (Wall Street Oasis):
In how many ways can you have three numbers that sum to 10? What about 11?
056You roll a fair die until each of 2, 4 and 6 has appeared at least once. Given that the last even number to make its first appearance was 2, what is the probability that the very first roll was a 1? Why is it not 1/5?Squarepoint CapitalLondon · 2026
Try it first
Given that 2 was the last even to show up, what is the chance the first roll was a 1?
Show the worked solution
1/6, the same as with no information. An odd first roll says nothing about the order in which 2, 4 and 6 first appear, so it is independent of 2 finishing last. A first roll of 4 or 6 raises the chance 2 is last from 1/3 to 1/2, so conditioning on that ending shifts weight onto 4 and 6, which rise to 1/4 each. The odd faces keep 1/6 each; 1/5 wrongly spreads the weight evenly.
Why does the ending tell you anything about the start?
Suppose you hear that a friend reached a party last. That makes it a little more likely they left home late, because leaving late and arriving last go together. It says nothing about whether they wore a blue shirt, which has no bearing on arrival order. Conditioning on an outcome reweights every starting state by how likely that state makes the outcome, and a state that does not affect the outcome keeps its original probability. Here the outcome is 2 finishing last among the evens; the question is which first rolls make that more or less likely.
A first roll of 1, 3 or 5 leaves 2 a one in three chance of finishing last, a first roll of 4 or 6 raises it to one in two, and a first roll of 2 makes it impossible, so given that 2 finished last the odd faces are worth 1/6 each and 4 and 6 are worth 1/4 each. How do the numbers work out with Bayes?
Odd rolls never change which new even appears next, so only the order of first appearances matters, and without information it is a random ordering of three: 2 is last with chance 1/3. If the first roll is 4, then 2 and 6 are left to race, and each is equally likely to show first, so 2 ends last with chance 1/2. Now weigh: each face has prior 1/6. The joint chance of first roll 1 and 2 last is 1/6 x 1/3 = 1/18; of first roll 4 and 2 last, 1/6 x 1/2 = 1/12. The total is 1/3, so first roll 1 has posterior (1/18)/(1/3) = 1/6 and first roll 4 has (1/12)/(1/3) = 1/4.
The relationship1/6 the prior chance of any face on the first roll 1/3 the chance 2 is last when the first roll is odd, and also overall 1/2 the chance 2 is last when 4 or 6 is already seen What it says in wordsAn odd first roll is independent of the ending and keeps 1/6; the even faces 4 and 6 absorb the weight that 2 loses.Where does the 1/5 intuition go wrong?
It treats the information as simply ruling out one face and renormalising the rest. Ruling out an outcome and conditioning on an event are the same thing only when every remaining outcome makes the event equally likely, and here they do not. A check: the posteriors 1/6, 1/6, 1/6, 1/4, 1/4 and 0 add to 1, while five faces at 1/5 would give 4 and 6 the same weight as 1. On a desk this is the error of reading a trade's outcome as if it said nothing about which signal triggered it.
Where candidates lose it
Nearly everyone's first answer is 1/5. The interviewer is not testing the arithmetic; the question itself says it is not 1/5 and asks you to explain why, so an answer that only produces 1/6 without the reason loses most of the credit.
The second trap is getting lost in the odd rolls. They can be ignored completely, because they never change which even appears next. Say that early and the problem shrinks to the order of three numbers.
What the interviewer asks next
- Given that 2 finished last, what is the probability the first roll was a 4?
- What is the expected number of rolls until all three evens have appeared?
- Given that 2 finished last, what is the probability the first even to appear was 4?
Asked at Squarepoint Capital, Quant Research Intern Interview, London, 2026 (Wall Street Oasis):
why is the probability of seeing a 1 on our first roll, given that we end on a 2, not 1/5
057Z is a standard normal random variable. What is the expected value of max(Z, 0), and what does that number tell you about the price of an at-the-money option?Quant researchQuant trading
Try it first
Roughly what is E[max(Z, 0)]?
Show the worked solution
1/sqrt(2 pi), about 0.399. Only the positive half contributes, and there you integrate z times the normal density. Because the derivative of the density is minus z times the density, the integral is simply the density's height at zero. So an at-the-money call on a normally distributed move is worth about 0.4 standard deviations of that move: roughly 0.4 x S x volatility x the square root of time.
Why is the answer not zero, and not one half?
Think of a shop that keeps the profit on good days and closes, losing nothing, on bad days. Its average day is better than the average of all days, because the bad days have been floored. max(Z, 0) throws away every negative outcome and keeps every positive one at its full size, so its mean is the positive half's contribution alone: the integral of z times the density from zero to infinity. That is not one half, which is only the chance of being positive; the size of each positive draw matters too.
The shaded area under z times the normal density on the positive side is exactly 0.399, the same as the density's peak height, so an at-the-money call on a normal move of one standard deviation is worth about 0.4, which for a Rs 1,000 stock at 20% volatility over three months is about Rs 40. How do you do the integral in one line?
Notice what differentiating the density gives. The derivative of e to the minus z squared over 2 is minus z times itself, so z times the density is the negative derivative of the density, and its integral from 0 to infinity is the density at 0 minus the density at infinity. The density at infinity is zero, and at zero it is 1/sqrt(2 pi). No tables, no substitution: the answer is 0.3989. Doubling it gives E[|Z|], about 0.798, which is the at-the-money straddle.
The relationshipphi(z) the standard normal density, e^(-z^2/2) / sqrt(2 pi) phi(0) the height of the density at its peak What it says in wordsThe expected positive part of a standard normal equals the height of the bell at its centre.What does it say about an at-the-money option?
If the stock's move to expiry is roughly normal with standard deviation S x vol x sqrt(T), an at-the-money call pays the positive part of that move. So its value is about 0.4 x S x vol x sqrt(T), the rule of thumb option traders use to price at-the-money options in their heads. For a Rs 1,000 stock at 20% volatility and three months, sqrt(T) is 0.5 and the call is about 0.399 x 1,000 x 0.2 x 0.5 = Rs 39.9; the Black-Scholes value with zero rates is Rs 39.88. The rule loosens for long maturities and high volatilities, where the lognormal skew matters.
Where candidates lose it
The two fast wrong answers are 0, from averaging Z itself, and 0.5, from confusing the probability of a positive draw with its expected size. Both come from answering before writing down what is being averaged.
The second loss is getting 0.399 and not connecting it to options, which is why the question is asked on a trading desk. Say the 0.4 rule in the same breath.
What the interviewer asks next
- What is E[max(Z, 1)]?
- What is the variance of max(Z, 0)?
- Using the rule, what is an at-the-money straddle worth on a Rs 500 stock at 30% volatility for one month?
058A bet pays 2 to 1 and wins 40% of the time. What fraction of your bankroll does the Kelly criterion stake on each bet, what long-run growth rate does that give, and what happens if you bet twice that fraction?Quant tradingOptions market making
Try it first
At twice the Kelly stake, what happens to long-run growth?
Show the worked solution
Stake 10% of the bankroll; that grows wealth by about 0.97% a bet, and twice Kelly grows it by only about 0.07%. Kelly is edge over odds: (2 x 0.4 - 0.6)/2 = 0.1. The growth rate is 0.4 ln(1.2) + 0.6 ln(0.9). At 20% the losses compound away almost the whole edge, and above about 20.4% the bankroll shrinks in the long run despite a positive expected value.
Why not bet as much as possible on a good bet?
Think of a shopkeeper with a profitable weekly sale who puts the entire shop's stock on it every week. The average week is good, but one bad week ends the business. With repeated bets, wealth multiplies, so what matters is the average of the log of each outcome, not the average outcome, and a big loss costs more in log terms than an equal gain earns. This bet has a clear edge: each rupee staked returns 0.4 x 2 - 0.6 = Rs 0.20 on average. The question is how much of that edge survives compounding at each stake size.
How do you get the Kelly fraction and the growth rate?
Stake a fraction f. A win multiplies wealth by 1 + 2f, a loss by 1 - f, so the growth per bet is g(f) = 0.4 ln(1 + 2f) + 0.6 ln(1 - f). Set the derivative to zero: 0.8/(1 + 2f) = 0.6/(1 - f), giving f = 0.1. The Kelly stake is the edge divided by the odds, (bp - q)/b = 0.2/2 = 10%. Plugging in, g = 0.4 x 0.1823 - 0.6 x 0.1054, about 0.97% a bet, so the typical path doubles its wealth roughly every 71 bets.
Long-run growth peaks at 0.97% a bet at the Kelly stake of 10%; half Kelly keeps 76% of that growth, twice Kelly keeps almost none of it at 0.07%, and any stake above about 20.4% shrinks the bankroll over time. The relationshipb the net odds, 2 to 1 p, q the chances of winning and losing, 0.4 and 0.6 g(f) expected log growth of wealth per bet at stake f What it says in wordsKelly maximises the expected log of wealth, and its stake is the edge divided by the odds.Why is overbetting so much worse than underbetting?
Near the peak the growth curve is close to a parabola, so the cost of a sizing error grows with its square. Half Kelly gives up only about a quarter of the growth, while twice Kelly gives up nearly all of it, and three times Kelly shrinks wealth at about 2.6% a bet. Real edges are estimated, not known, so a trader who thinks the win rate is 40% but faces 35% is already overbetting at the full 10%. That asymmetry is why desks size at a fraction of Kelly.
Where candidates lose it
The first trap is stopping at the positive expected value and saying bet big. The interviewer is testing whether you know that repeated multiplicative bets are judged by log growth, where volatility itself costs money.
The second is misremembering the formula as p - q or as p/b. Derive it from the log growth in two lines; it is faster than recalling and it proves you know where it comes from.
What the interviewer asks next
- What is the Kelly fraction for an even-money bet that wins 55% of the time?
- Why might a trader deliberately stake half Kelly?
- How would you size two independent simultaneous bets like this one?
059We play a coin game. I pick a sequence of three heads or tails, you then pick a different sequence after seeing mine, and we flip a fair coin until one of the two sequences appears; whoever's comes first wins. I pick HHH. What do you pick, and how often do you win?Quant tradingProp trading firms
Try it first
Which reply to HHH is best?
Show the worked solution
Pick THH; you win 7 times in 8. HHH can only win if the first three flips are all heads, which has chance 1/8. In any other run, the first HHH is preceded by a tail, and that tail with the next two heads spells THH, which is completed one flip before HHH. So THH wins every game except the one that opens with three heads.
Why is this not a fair race between two 1/8 sequences?
Think of two runners on the same track where one always starts one step ahead of the other on the only route to the finish. Their speeds are identical but the race is not even. In a race between patterns, what matters is not how often each appears but which one tends to appear first, and that depends on how the patterns overlap. THH is built from HHH's own first two heads with a tail placed in front, so it ambushes HHH whenever HHH has not already won at the start.
HHH wins only when the first three flips are heads, a 1/8 chance; in every other run the first HHH is preceded by a tail, so THH is completed one flip earlier and wins the remaining 7/8 of games. How do you prove 7/8 without a Markov chain?
Look at the first time HHH appears. If it does not start at flip 1, the flip immediately before it must be a tail, because otherwise an earlier HHH would already have appeared. That tail plus the first two heads of the HHH is THH, finished one flip before HHH. So HHH wins only if flips 1 to 3 are heads, chance 1/8, and THH wins otherwise: 7/8. The proof is one sentence, and interviewers want to hear it rather than a transition matrix.
What is the general lesson for the second mover?
This is Penney's gameA coin sequence race in which the second player, choosing after seeing the first, can always pick a sequence that wins more than half the time., and the second player always has an edge because the winning relation among three-flip sequences is not transitive: every sequence has another that beats it. The recipe: take the opponent's first two flips, and put in front of them the opposite of the opponent's second flip. Against HHH that gives THH at 7/8; against HTH it gives HHT at 2/3. In trading terms, a strategy that looks as good as any other in isolation can still lose systematically to one designed around it.
Where candidates lose it
The trap is answering that every sequence has probability 1/8, so the game is fair, or picking TTT because it has nothing in common with HHH. Both treat the race as independent draws of three flips rather than a stream where patterns overlap.
The second trap is reaching for a four-state Markov chain and running out of time. The tail-before-the-run argument settles it in one sentence; set up the chain only if asked about a harder pair.
What the interviewer asks next
- I pick HTH. What do you pick, and how often do you win?
- What is the expected number of flips to see HHH, and to see THH?
- Why can no three-flip sequence be the best first choice?
060In how many ways can you place four queens on a 4 by 4 board so that no queen attacks another? How would you organise the search, and what does the same method give for five queens on a 5 by 5 board?Goldman SachsNew York · 2026
Try it first
How many non-attacking placements of four queens exist on a 4 by 4 board?
Show the worked solution
Two on a 4 by 4 board and 10 on a 5 by 5 board. Place one queen per row, trying columns left to right, and abandon a branch the moment the next row has no safe column. On 4 by 4 this visits 16 placements and finds columns 2, 4, 1, 3 and 3, 1, 4, 2. On 5 by 5 the same search visits 53 placements, against 3,125 boards for brute force.
How do you organise the search so it stays small?
Think of filling a seating plan for a wedding where some guests cannot sit near each other. You seat table by table, and the moment a table has no acceptable guest left you undo the previous choice instead of finishing a doomed plan. Backtracking builds the answer one decision at a time and abandons a partial answer as soon as it breaks a rule, so it never enumerates the boards that fail early. For queens, two rules come free from the structure: one queen per row, and one per column, which leaves only the diagonals to check at each step.
Row by row, the search tries 16 placements on the 4 by 4 board; four branches die when a row has no safe column, and two reach row 4, giving the solutions 2, 4, 1, 3 and 3, 1, 4, 2. How does the 4 by 4 search actually run?
Start with the corner. A queen in column 1 of row 1 leaves row 2 only columns 3 and 4, and both paths run out of safe squares by row 3 or row 4, so no solution uses a corner queen. A queen in column 2 forces column 4 in row 2, then column 1 in row 3 and column 3 in row 4, which works. Columns 3 and 4 are mirror images of 2 and 1. So there are exactly two solutions, and they are reflections of each other. Saying the symmetry out loud halves the work and is exactly what an interviewer building up from a base case wants to hear.
What changes on 5 by 5, and how does the method scale?
The larger board has more room, and every row 1 column leads somewhere. The same search finds 10 solutions after 53 placements, while brute force over one queen per row would test 3,125 boards. On 8 by 8 it finds all 92 solutions in 2,056 placements out of 16,777,216 one-per-row boards. In code, keep three sets, used columns, used down-diagonals (row minus column) and used up-diagonals (row plus column), so each safety check is constant time.
Where candidates lose it
Candidates start listing boards by eye and lose track, or they try all C(16, 4) = 1,820 ways to place four queens anywhere. The interviewer wants the structure: one per row, a column choice per row, and pruning.
The second loss is counting the two 4 by 4 solutions as four or eight by treating rotations as new. Say whether you count symmetric boards as distinct, and note that here the two solutions are each other's mirror image.
What the interviewer asks next
- Write the backtracking function and state its time complexity in the worst case.
- How would you count solutions up to rotation and reflection?
- Why do the 2 by 2 and 3 by 3 boards have no solution at all?
Asked at Goldman Sachs, Quantitative Research, New York, 2026 (Wall Street Oasis):
I was asked a backtracking question in 1 of the rounds in the superday.

