Quant puzzles, solved step by step
- Puzzles
- 100
- Traced to a firm
- 71
- Topics
- 12
- Hard
- 30
004You keep drawing independent random numbers, each uniform on 0 to 1, until their running total exceeds 1. What is the expected number of draws?Citadel SecuritiesChicago · 2025
Try it first
What is your instinct for the answer?
Show the worked solution
e, about 2.718. The chance that n uniforms still add to at most 1 is 1/n!, the volume of a corner of the n-dimensional cube. The number of draws N exceeds n exactly when that happens, and an expected count is the sum of the chances of exceeding each n. So E[N] is 1 + 1 + 1/2 + 1/6 + 1/24 and so on, which is e.
Why is two draws the wrong answer?
Fill a one litre jug with cups of random size, each somewhere between empty and full. On average two cups make a litre, but you stop at the first cup that overflows, and some pairs of cups fall short. Averages of the draws do not tell you the average stopping time: you need the chance that you are still short after each draw. After two draws you are still at or below 1 exactly half the time, so a third draw is needed often, and occasionally a fourth.
The chance of still being at or below 1 after n draws is 1/n!, so the bars run 1, 1, 1/2, 1/6, 1/24, and their running sum, the expected number of draws, closes in on e, about 2.718. Where does 1/n! come from?
For two draws, the pairs with a total at or below 1 fill the triangle under the line x + y = 1 in the unit square, area 1/2. For three, they fill a corner of the unit cube, volume 1/6. In general the region where n uniforms add to at most 1 is a corner of the n-dimensional cube with volume 1/n!, because the n! orderings of the coordinates carve the cube into equal pieces. You can also build it by convolutionThe density of a sum of independent variables, found by combining every way the parts can add up to the same total.: the density of the sum below 1 is s to the power n-1 over (n-1)!, and integrating from 0 to 1 gives 1/n!.
The relationshipN the number of draws needed P(N > n) the chance that n draws were not enough U_i the uniform draws What it says in wordsThe expected count equals the sum over n of the chance that n draws were still not enough, and those chances are 1/n!.How do you check an answer this surprising?
Check the pieces. N is at least 2 always, since one draw never exceeds 1, so the answer must be above 2; the bars for n = 0 and n = 1 are both 1 for that reason. A simulation of 200,000 runs gives an average of 2.721 draws, within a whisker of 2.718. Saying that you would simulate it, and roughly what you expect to see, is a good close in a research interview.
Where candidates lose it
The instinctive answer is 2, because two draws average exactly 1. It confuses the average of the draws with the average stopping time, and it ignores that the stopping rule waits for the total to pass 1, not reach it on average.
The second loss is knowing the answer is e without being able to say why. The tail-sum formula for an expected count, plus the 1/n! volume, is the whole argument, and it takes three sentences.
What the interviewer asks next
- What is the expected number of draws to exceed 2?
- What is the expected value of the total at the moment it first exceeds 1?
- What is the probability that exactly two draws are needed?
Asked at Citadel Securities, Quant Research Interview, Chicago, 2025 (Wall Street Oasis):
He was asking some questions about the probability, especially on the convolution.
010A company's value to its current owner is equally likely to be anything from Rs 0 to Rs 100 crore, and only the owner knows the figure. In your hands the company would be worth 1.5 times that value. You may make one take-it-or-leave-it offer, which the owner accepts only if it is at least the company's value to them. What should you bid?Quant tradingQuant research
Try it first
Which bid maximises your expected profit?
Show the worked solution
Bid nothing. If a bid of b is accepted, the owner has told you the company is worth less than b to them, so its value is uniform on 0 to b and averages b/2. In your hands that is 1.5 x b/2 = 0.75b, a quarter less than you paid. Expected profit is (b/100) x (0.75b - b) = -b squared/400, negative for every positive bid. This is the winner's curse in its purest form.
Why does 75 look right and fail?
Picture buying a used car from someone who knows its history while you do not. If they agree to your price at once, that is itself news: sellers of good cars refuse low offers. Acceptance is not random; it happens exactly in the states where the company is worth less than you offered, so the average value you actually receive is the average below your bid, not the average overall. The naive 75 uses the unconditional average of 50 and forgets that you only trade when the owner is happy to sell.
The naive line values the company at its overall average and shows profit for any bid under 75, but conditioning on the owner accepting gives expected profit of minus b squared over 400, which is below zero for every positive bid, minus 6.25 crore at a bid of 50. How do you set up the expected profit?
Split it into the chance of a deal and the profit given a deal. A bid of b is accepted with probability b/100; given acceptance the owner's value is uniform on 0 to b, averaging b/2, so your value averages 0.75b and your profit averages minus 0.25b. Multiply: minus 0.25b x b/100, which is minus b squared over 400. At a bid of 50 that is minus 6.25 crore: you win half the time and lose 12.5 crore on average when you do.
The relationshipb your bid in Rs crore b/100 the chance the owner's value is below b b/2 the owner's average value, given that they accepted What it says in wordsThe chance of winning times the loss when you win is negative for every positive bid.When would bidding make sense, and where does this show up on a desk?
The multiplier is the lever. With a multiplier m, the profit given a deal is (m/2 - 1)b, so bidding pays only if you add more than double the owner's value; at exactly 2 you break even, and above 2 you should bid the full 100. On a trading desk the same logic is called adverse selectionThe tendency for the trades you actually get to come from counterparties with better information than you, so they are worse on average than a random trade.: the orders that fill against you are disproportionately the ones from people who know more. A quote that looks profitable against the average counterparty loses against the ones who choose to trade.
Where candidates lose it
Most candidates bid somewhere between 50 and 75, reasoning from the unconditional average value. That ignores the information in the owner's acceptance, which is the entire point of the question.
The second loss is a partial fix: realising acceptance is informative but then bidding a little lower, such as 60, to leave a margin. Any positive bid loses here. Write the expected profit as a function of b and let the algebra say zero.
What the interviewer asks next
- What multiplier would make you willing to bid, and how much would you then bid?
- What if the owner's value is uniform on 50 to 100 instead?
- How does this relate to a market maker who gets filled on their quotes?
016You need to sample a point uniformly at random from a triangle with vertices A, B and C, using two independent uniform numbers u and v on 0 to 1. How do you do it, and why does the formula A + u(B - A) + v(C - A) fail on its own?Two SigmaNew York · 2023
Try it first
What goes wrong with A + u(B - A) + v(C - A) for u, v uniform on 0 to 1?
Show the worked solution
Draw u and v; if u + v is above 1, replace them with 1 - u and 1 - v; then return A + u(B - A) + v(C - A). The plain formula maps the unit square onto a parallelogram twice the size of the triangle, so half the draws, 50.0% in a simulation, land outside. Reflecting through the square's centre folds that half exactly onto the other, keeping the density flat and wasting no draws.
Why does the plain formula give a parallelogram?
Think of a tiled floor where each tile is a parallelogram and you want to pick a spot on one triangular half of a tile. Pick any spot on the tile and half the time you are on the wrong half. A + u(B - A) + v(C - A) with u and v each free on 0 to 1 walks up to one full step along AB and one full step along AC, which covers the parallelogram with corners A, B, C and D = B + C - A, not the triangle. The triangle is exactly the part where u + v is at most 1.
Two uniforms fill a unit square that the linear map turns into a parallelogram twice the size of triangle ABC, so draws with u + v above 1 land outside; reflecting such a draw from (0.8, 0.6) to (0.2, 0.4) brings it back inside at a uniformly distributed spot. Why does reflecting keep the distribution uniform?
Two facts. The map (u, v) to (1 - u, 1 - v) is a half turn about the square's centre, so it carries the upper triangle onto the lower one without stretching any area; and an affine mapA linear map followed by a shift, such as A + u(B - A) + v(C - A); it scales every area by the same factor. scales every area by the same factor, so a flat density stays flat. Put together, each small patch of the triangle receives draws from exactly two equal patches of the square. A simulation that splits the triangle into four equal pieces finds 24.9%, 25.1%, 25.0%, 25.0% of the points in them, each a quarter.
The relationshipu, v independent uniforms on 0 to 1 (1-u, 1-v) the reflection of a draw through the square's centre P the sampled point, uniform on triangle ABC What it says in wordsFold the unwanted half of the square onto the wanted half, then map it linearly onto the triangle.What other methods would an interviewer accept, and which fail?
Rejection works: throw away draws with u + v above 1. It is correct but wastes half the random numbers. A popular wrong method draws three uniforms and divides each by their sum to get weights on A, B and C; the weights add to 1, but the points pile up near the centre, so the result is not uniform. A correct closed form uses a square root: with r1 and r2 uniform, take (1 - root r1)A + root r1 (1 - r2)B + root r1 r2 C. Name one fast method, prove it, then name the tempting wrong one.
Where candidates lose it
The trap is writing the linear formula and stopping, because it looks like a weighted average of the vertices. Half the points leave the triangle, and the candidate who does not draw the square never sees it.
The second loss is fixing the problem in a way that breaks uniformity, such as normalising random weights to sum to 1 or clamping u + v to 1. Both keep points inside but crowd them into part of the triangle. Say why your fix preserves area.
What the interviewer asks next
- Prove the square-root method gives a uniform point.
- How would you sample uniformly from a convex polygon with n vertices?
- How would you sample uniformly from the surface of a sphere?
Asked at Two Sigma, Research, New York, 2023 (Wall Street Oasis):
Biased gamblers ruin problems; Markov Chain problems; sampling uniformly from triangle
017The true model is y = x1 + x2 + noise, where x1 and x2 are standardised and have correlation 0.5. You regress y on x1 alone, then regress the residuals on x2. What coefficient do you get on x2, and how would you recover the true value of 1 in two stages?Quant researchQuant trading
Try it first
What coefficient does the second stage give on x2?
Show the worked solution
You get 0.75, not 1. Regressing y on x1 alone gives a slope of 1 + 0.5 = 1.5, because x1 soaks up the half of x2 that moves with it. The residual is x2 - 0.5x1 + noise, whose slope on x2 is 1 - 0.5 squared = 0.75. To recover 1, residualise x2 on x1 as well and regress the residual of y on the residual of x2: the Frisch-Waugh-Lovell theorem.
Where does the missing quarter go?
Picture two salespeople who often work the same client. If you credit all joint sales to the first before looking at the second, the second looks worse than they are, because some of their work was already booked to the first. Stage one regresses y on x1 alone, and since x2 is correlated with x1, the coefficient on x1 rises to 1.5: it takes credit for 0.5 of x2. That piece has been removed from the residual, so stage two can only find what is left of x2's effect.
With a correlation of 0.5, x2 splits into 0.5 x1 plus an orthogonal part; stage one assigns the 0.5 x1 piece to x1, so regressing the residual on raw x2 gives 0.75, while regressing it on the orthogonal part of x2 recovers the true 1. How do you get 0.75 exactly?
Write the residual out. y - 1.5x1 = x2 - 0.5x1 + noise, and the slope of that on x2 is its covariance with x2 over the variance of x2: (1 - 0.5 x 0.5)/1 = 0.75. The formula generalises to 1 - rho squared times the true coefficient, so the bias gets worse as the regressors get more correlated: with rho = 0.9 you would find only 0.19. A simulation of 100,000 observations gives 1.506 for stage one and 0.752 for stage two.
The relationship\rho the correlation between x1 and x2, 0.5 x_2 - \rho x_1 the part of x2 left after regressing it on x1 What it says in wordsRegressing on raw x2 shrinks the answer by one minus rho squared; regressing on the part of x2 orthogonal to x1 gives the true coefficient.What does Frisch-Waugh-Lovell tell you to do?
To get a variable's coefficient from a multiple regression in stages, partial the other regressors out of both y and that variable, then regress residual on residual. Here that means regressing x2 on x1 as well, keeping the orthogonal part x2 - 0.5x1, and regressing the stage-one residual on it. The slope comes back as exactly 1; the simulation gives 1.003. This is why factor-neutralising a signal before testing it, rather than after, matters in quant research: the order of the stages changes the answer.
Where candidates lose it
The common answer is 1, on the belief that regressing residuals step by step is the same as a multiple regression. It is only the same when the regressors are uncorrelated, and the question gives you a correlation of 0.5 precisely to break that.
The second loss is saying the answer is biased without saying which way or by how much. Give 1.5 for stage one, 0.75 for stage two, the 1 - rho squared rule, and the fix.
What the interviewer asks next
- What would the stage-two coefficient be if the correlation were -0.5?
- In the two-stage FWL regression, how do the standard errors compare with the full multiple regression?
- You have a new signal correlated with a known factor. How do you test whether it adds anything?
019A casino flips a fair coin until the first head appears and pays 2 to the power n rupees if that happens on flip n. Its bank holds only 2 to the power 20 rupees, so it pays at most that. What is the fair price of the game?Hudson River TradingNew York · 2020
Try it first
What is the fair price with the bank capped at 2 to the 20 rupees?
Show the worked solution
Rs 21. Flip n pays 2 to the n with probability 1/2 to the n, so each of flips 1 to 20 contributes exactly 1 rupee: 20 rupees. Beyond flip 20 the casino pays its whole bank, 2 to the 20, and the chance of getting that far is 1/2 to the 20, which adds 1 more. The famous infinite value collapses to 21 as soon as the payer's bank is finite.
Why is the uncapped game worth infinity?
Each extra flip halves the chance and doubles the prize, so each flip adds the same 1 rupee to the average, forever. An expected value is a sum over outcomes of prize times chance, and when every term is 1 and there are infinitely many terms, the sum has no limit. That is the St Petersburg paradox, discussed by Daniel Bernoulli in the eighteenth century: the mathematics says pay anything, and nobody would pay more than a modest sum.
Every flip up to the twentieth contributes exactly 1 rupee to the expected value, and the capped payouts beyond it add up to just 1 more, so a casino with a bank of 2 to the 20 rupees offers a game worth Rs 21. What exactly does the cap remove?
Picture a lottery that promises to double your prize every day for ever, run by a shop with a small safe. The later promises are worth nothing because the shop cannot keep them. The cap turns every term after flip 20 from 1 rupee into 2 to the 20 divided by 2 to the n, which is 1/2, 1/4, 1/8 and so on, and those add up to exactly 1. So the tail that made the value infinite is now worth a single rupee. The bank is Rs 10,48,576 and the game is worth Rs 21.
The relationship2^n the payout if the first head arrives on flip n 2^{-n} the chance the first head arrives on flip n 2^{20} the bank, which caps every later payout What it says in wordsTwenty flips worth a rupee each, plus a capped tail worth one rupee.What does this teach about pricing a payoff?
Doubling the bank adds only one rupee to the fair price: a bank of 2 to the 30, about Rs 107 crore, makes the game worth Rs 31. The value grows with the logarithm of what the counterparty can pay, so the realistic price of a lottery-like payoff depends on who stands behind it. The same idea appears in trading as counterparty risk: a contract's promised payout in extreme states is only worth what the other side can deliver in those states.
Where candidates lose it
Candidates recite the St Petersburg paradox and answer infinity, missing the cap in the question. The interviewer has changed one word to see whether you hear it.
The second loss is getting 20 by stopping at the cap and forgetting the tail. Every sequence of 20 tails still pays the full bank, and that last piece is worth exactly one more rupee.
What the interviewer asks next
- How big must the bank be for the game to be worth Rs 50?
- How much would a player with logarithmic utility pay for the uncapped game?
- If you could play the capped game a million times, how would the average payout behave?
Asked at Hudson River Trading, Prop Trading, New York, 2020 (Wall Street Oasis):
Questions on EV for coin tosses, law of large numbers, Bayes theorem
022A three-way duel: you hit your target with probability 1/3, B with 2/3, and C never misses. You shoot first, then B, then C, repeating in that order until one person is left, and everyone aims to maximise their own survival. Where should you aim your first shot?Quant tradingQuant research
Try it first
Which first shot gives you the best chance of surviving?
Show the worked solution
Fire into the air. B and C each target the other, the bigger threat, so while both live nobody shoots at you. Aiming in the air gives survival of 2/3 x 3/7 + 1/3 x 1/3 = 25/63, about 39.7%. Aiming at C gives 31.2%, because a hit leaves you in a duel with B shooting first. Aiming at B gives 26.5%, because a hit leaves C, who never misses, to shoot you.
Who does everyone else aim at?
Start with the stronger players, because their choices fix yours. B aims at C, because if B shot you instead, C would kill B next turn for certain; C aims at B, the more dangerous of the two remaining threats. So while all three are alive, nobody is shooting at you. Think of two large firms in a price war while a small competitor stays out of it: the small firm's best move is often to let the giants weaken each other.
Firing into the air gives you 39.7% survival, against 31.2% for aiming at C and 26.5% for aiming at B, because hitting either rival makes you the survivor's only target while missing on purpose lets B and C shoot at each other first. How do you work out the two-player duels?
Against B with you shooting first, you win if you hit now, or if both miss and the same duel restarts. Call your survival x: x = 1/3 + (2/3)(1/3)x, so x = 3/7; if B shoots first, you must survive B's first shot, 1/3 of the time, giving 1/7. Against C you get exactly one shot, since C never misses: 1/3 if you shoot first, 0 if C does. Now combine. In the air: B hits C two times in three, giving you the 3/7 duel; otherwise C kills B and you get your one shot at C, 1/3. Total 25/63.
The relationship3/7 your survival in a duel with B when you shoot first 1/7 your survival in a duel with B when B shoots first 25/63 your survival after a deliberate miss What it says in wordsMissing on purpose beats both targeted shots: 75/189 against 59/189 and 50/189.What is the general lesson?
In a game with several players, weakening one rival can hurt you if it frees the strongest remaining player to turn on you. Your best shot is the one that keeps the others focused on each other. Say the limitation too: the answer depends on the hit rates and the order. Change the order of shooting, or let C aim at you, and the tree changes; the interviewer will often change a number or the order to see whether you rebuild the tree or repeat the slogan.
Where candidates lose it
The instinctive answer is to shoot at C, the most dangerous player. It ignores what happens after a hit: you have just made yourself B's only target, and B shoots first.
The second loss is assuming that firing into the air is allowed but not checking it is optimal. Candidates who have heard the answer before often cannot produce 25/63, 59/189 and 50/189 when asked. The numbers are the answer; the slogan is not.
What the interviewer asks next
- What if your hit rate were 1/2 instead of 1/3?
- What if C shot first and you shot last?
- What is B's overall survival probability when you fire into the air?
023You flip a fair coin until the pattern HTH appears. What is the expected number of flips? Why is it larger than the expected wait for HTT, when each pattern has the same probability of 1/8 at any given position?Quant tradingQuant research
Try it first
Expected flips to see HTH?
Show the worked solution
10 flips for HTH, against 8 for HTT. Track how much of the pattern you currently hold: nothing, H, or HT. For HTH, a tail after HT wrecks everything and you restart from nothing. For HTT, a head after HT breaks the pattern, but that head is itself a fresh start, so you keep an H. Solving the three expected-wait equations gives 10 and 8.
Why do equal probabilities give unequal waits?
Think of a combination lock where a wrong digit sometimes resets you to zero and sometimes lets you keep part of your progress. Two combinations can be equally likely to be dialled at random yet take different times to reach. Each three-flip window is HTH or HTT with the same 1/8 chance, but the windows overlap, and HTH occurrences tend to arrive in clusters, such as HTHTH, which spaces out the first appearance. The waiting time depends on where a near miss leaves you.
Waiting for HTH, a tail from state HT sends you back to the start and the average wait is 10 flips; waiting for HTT, a head from HT leaves you holding an H and the average wait is only 8. How do you set up the equations?
Let E0, E1 and E2 be the expected remaining flips when you hold nothing, H and HT. Each flip costs one and moves you to the next state with probability one half each way, so each state's wait is 1 plus the average of the two states it can move to. For HTH: E0 = 1 + (E1 + E0)/2, E1 = 1 + (E1 + E2)/2, E2 = 1 + (0 + E0)/2. Solving gives E2 = 6, E1 = 8, E0 = 10. For HTT only the last equation changes, to E2 = 1 + (0 + E1)/2, and the answers become 4, 6 and 8.
The relationship2^3 from the whole pattern matching itself 2^1 from HTH's last flip matching its first: the pattern overlaps itself What it says in wordsFor a fair coin, add 2 to the power k for every length k at which the pattern's start equals its end.Is there a shortcut an interviewer will accept?
Yes, the overlap rule, which comes from a fair-bet argument known as the ABRACADABRA methodA martingale argument in which gamblers arriving each flip bet on the pattern, used to compute expected waiting times for patterns.. For a fair coin, the expected wait is the sum of 2 to the k over every k where the first k flips of the pattern equal the last k. HTH matches itself at length 3 and at length 1, the single H, giving 8 + 2 = 10. HTT matches only at length 3, giving 8. HHH matches at 1, 2 and 3, giving 14. Derive the states first, then offer the rule as the check.
Where candidates lose it
The trap is answering 8 for every three-flip pattern, reasoning that each has probability 1/8 per window. That confuses frequency with first arrival: over a long run both patterns appear equally often, but HTH comes in overlapping clumps.
The second loss is getting the fall-back wrong in the state diagram. For HTT, after HT a head is not a return to nothing; it is a new H. Drawing that arrow to the start gives 10 for both and hides the whole point.
What the interviewer asks next
- What is the expected wait for HHH?
- Two players race, one waiting for HTH and one for HTT on the same flips. Who is more likely to win?
- With a biased coin that shows heads 60% of the time, what is the expected wait for HTH?
029Rs 1 was invested in a broad stock index 30 years ago. If yearly log returns are independent with mean 7% and standard deviation 16% (illustrative inputs), give a median and a 95% interval for what it is worth today.Old Mission CapitalChicago · 2025
Try it first
Which is the best central 95% range for the Rs 1 today?
Show the worked solution
Median about Rs 8.2; 95% interval roughly Rs 1.5 to Rs 45. Log returns add, so after 30 years the log of wealth has mean 30 x 0.07 = 2.1 and standard deviation 0.16 x √30 = 0.88. The median is e to the 2.1, about 8.2. The band is e to the power 2.1 plus or minus 1.96 x 0.88. In rupees it is lopsided, and the mean, about Rs 12, sits above the median.
Why work in log returns rather than percentage returns?
Pay rises compound: 10% and then another 10% is 21%, not 20%. Logs turn that multiplication into addition. Log returns add across years, so the 30-year log return is a sum of 30 yearly pieces, and a sum of independent pieces is close to normal. With mean 0.07 and standard deviation 0.16 a year, the sum has mean 2.1 and variance 30 x 0.16 squared, so a standard deviation of 0.16 x √30, about 0.876. The spread grows with the square root of time, not with time.
The relationshipW_30 value of the Rs 1 after 30 years mu = 0.07 mean yearly log return, an illustrative input sigma = 0.16 standard deviation of the yearly log return 1.96 the number of standard deviations that cuts off 2.5% in each tail of a normal What it says in wordsBuild the interval for the log of wealth, where it is symmetric, then exponentiate the two ends.On a log scale the 95% band is symmetric around the median of Rs 8.2, running from Rs 1.5 to Rs 45.5; on an ordinary rupee scale the same band reaches Rs 6.7 below the median and Rs 37.3 above it, and the mean of Rs 12.0 sits right of the median. Why is the band so lopsided, and where does the mean sit?
Symmetric in the exponent means lopsided in rupees. Going 1.96 standard deviations down divides the median by e to the 1.72, a factor of 5.6; going the same distance up multiplies by 5.6. Dividing and multiplying by the same factor leaves Rs 6.7 of room below the median and Rs 37.3 above it. The same skew separates mean from median. The mean of a lognormalA variable whose logarithm is normally distributed; it is always positive and skewed to the right. variable is e to the power (mean plus half the variance), about Rs 12.0 here, because a few very good paths pull the average up while most paths finish below it.
Close with the limits. The 7% and 16% are illustrative inputs, not a claim about any real index. The calculation assumes independent years and constant volatility; real markets have fat tails and calm and stormy regimes, so treat the band as a floor on the true uncertainty. What the interviewer is testing is whether you scale the mean with t and the volatility with √t, and exponentiate only at the end. One useful extra: the chance the Rs 1 is worth less than Rs 1 is the chance the log falls below zero, about 0.8%.
Where candidates lose it
The most common slip is building the interval in rupees: take 8.2 and add and subtract a symmetric amount, which can even run below zero. Build it in logs and exponentiate the two ends.
The second is scaling the 16% by 30 instead of √30, which gives a log standard deviation of 4.8 and a band from paise to crores. Variance adds across years; standard deviation grows with the square root.
What the interviewer asks next
- What is the probability the Rs 1 is worth less than Rs 1 today?
- If you are given the average percentage return rather than the average log return, how do you convert?
- How does the band change over a 10-year horizon?
Asked at Old Mission Capital, Prop Trading, Chicago, 2025 (Wall Street Oasis):
Confidence interval of portfolio value if you invested $1 in S&P 500 30 years ago
030We play chess repeatedly. Each game is drawn with probability 1/2; of the decisive games I win 2/3 and you win 1/3. The match ends when one of us wins three games in a row, and a draw breaks any streak. What is the probability I win the match?Old Mission CapitalChicago · 2018
Try it first
Roughly what is my chance of winning the match?
Show the worked solution
86/99, about 86.9%. Track only the current streak: none, me on 1 or 2, you on 1 or 2. Each game I win with probability 1/3, you win with 1/6, and a draw, 1/2, resets the streak. Write my chance of taking the match from each state in terms of the others, solve the five equations, and the start state comes out at 86/99.
What is the state, and why is the running score not it?
A door lock that opens after three correct codes in a row does not care how many wrong codes came before the last mistake. The only thing that matters for the rest of this match is the current streak, so the states are: no streak, my streak of 1 or 2, and your streak of 1 or 2. Games won earlier, draws played, games elapsed: all irrelevant once the streak is known. That is the Markov propertyThe future depends on the past only through the present state., and spotting it turns an infinite tree of game sequences into five numbers. Per game, I win with probability 1/2 x 2/3 = 1/3, you win with 1/2 x 1/3 = 1/6, and the rest are draws.
The match has five live states and two endings; solving one equation per state gives my chance of winning as 86/99 from the start, rising to 10/11 when I am on a streak of two and falling to 8/11 when you are. How do the equations go, and how do you solve them quickly?
Let x be my chance from the start, a1 and a2 from my streaks, b1 and b2 from yours. Every equation reads the same way: play one more game, three things can happen. A draw always returns to the start, a win for me always moves to a1 or one step up, and a win for you always moves to b1 or one step up. From a2 my next win ends the match in my favour; from b2 your next win ends it against me.
The relationshipx my chance of winning the match from a fresh start a1, a2 my chance when I have won the last one or two games b1, b2 my chance when you have won the last one or two games What it says in wordsEach state's value is the average of where the next game can send the match, weighted by the chance of each result.Solve by substituting: b2 is in terms of a1 and x, which gives b1 in the same terms; feed that into a2 and a1, and the start equation leaves one unknown. The answers: x = 86/99, a1 = 29/33, a2 = 10/11, b1 = 28/33, b2 = 8/11. Check the ordering: the further I am ahead, the higher the value, and every value sits between 0 and 1. Your chance is 13/99. A quick cross-check: three wins in a row is (1/3) cubed for me and (1/6) cubed for you, a ratio of 8 to 1, which would suggest about 89%; landing within two points of that rough race is a sign no term was dropped.
Where candidates lose it
Candidates often forget that a draw resets both streaks, or they let a draw keep a streak alive. The question says draws break any streak, which is why every state has a path back to the start, and dropping that path changes the answer.
The other loss is trying to add up sequences of games. The sequences never end; the states are five. Name the states first, write one line per state, and the problem becomes algebra.
What the interviewer asks next
- What if a draw does not break a streak?
- What is the expected number of games the match lasts?
- What if the match needs only two wins in a row?
Asked at Old Mission Capital, Prop Trading, Chicago, 2018 (Wall Street Oasis):
You and I play chess. 1/2 games end in draws and in the other half I win with 2/3 probability
031Take a random ordering of n distinct numbers and run exactly one left-to-right pass of bubble sort, swapping each adjacent pair that is out of order. What is the probability the list is fully sorted afterwards? Work it for n = 5.Jump TradingChicago · 2018
Try it first
For n = 5, how likely is the list sorted after one pass?
Show the worked solution
2 to the power (n - 1) divided by n factorial, which is 16/120 = 2/15 for n = 5. One pass moves every number that is not carried rightwards exactly one place left. So the list ends sorted only if no number starts more than one place right of its final spot. Placing 1, then 2, then 3 and so on, each has two allowed spots and the largest takes the last one, giving 2 to the power (n - 1) orderings.
What does one pass actually do to each number?
Picture a queue at a ticket window where the tallest person seen so far keeps stepping back past anyone shorter. That person travels a long way to the right; everyone they pass shifts one step forward. In one pass, the running maximum is carried right until it meets something larger, and every number it passes moves exactly one place left. Nothing moves left by two in a single pass. That limit is the whole problem.
In 3 1 2 5 4 every number starts at most one place right of its home, so one pass sorts it; in 2 3 1 4 5 the 1 starts two places right of home and ends one short, so only 16 of the 120 orderings of five numbers, 2 in 15, sort in one pass. Which orderings survive, and how do you count them?
Because a number can shift left by one at most, the list sorts only if each number starts no more than one place right of its home. The converse also holds: when every number meets that condition, the pass carries each big number to exactly where it belongs. For five numbers, a brute-force check of all 120 orderings finds exactly the 16 that meet the condition, and all 16 sort.
Now count them without listing. Place the numbers in increasing order. The 1 may sit in position 1 or 2. The 2 may sit anywhere in positions 1 to 3, one of which the 1 already took: two choices. The same holds for 3 and 4: each has k + 1 allowed spots, k - 1 of them already used by smaller numbers, so two choices each. The 5 fills the one position left. That is 2 x 2 x 2 x 2 x 1 = 16.
The relationship2^(n-1) orderings where no number starts more than one place right of its home n! all orderings of n distinct numbers, equally likely What it says in wordsTwo choices for each number except the largest, over all possible orderings.Check small cases out loud: for n = 2 both orderings sort, 2 of 2; for n = 3 it is 4 of 6. The probability collapses fast, because n factorial outruns 2 to the power n: about 4.4% for n = 6 and 1.3% for n = 7.
Where candidates lose it
The common wrong start is to think one pass only fixes the largest number, and answer that the other n - 1 must already be sorted, which gives 1/(n - 1)! and 1/24 for n = 5. It misses that every passed number also moves left one place, which rescues many orderings.
The other loss is guessing a rule from one example. State the one-step-left limit, derive the condition from it, then count by placing numbers in increasing order.
What the interviewer asks next
- What is the probability the list is sorted after two passes?
- How many passes does bubble sort need on average for a random list of n numbers, roughly?
- What if the pass runs right to left instead?
Asked at Jump Trading, Research, Chicago, 2018 (Wall Street Oasis):
one iteration of bubble sort, what's the probability that the array will be sorted
