Quick check in developer interviews.
The bug that only shows up in production
The question
Why should you not sum prices as floating point, and what do you do instead?
Have a go before you open the solution. If you are stuck after a few minutes, the first paragraph below is usually enough of a nudge.
Show the worked solution
The answer
Binary floating point cannot represent most decimal fractions exactly, so errors accumulate. Use integer minor units or a decimal type.
Values like 0.1 have no exact binary representation, so 0.1 added three times is not 0.3 and equality comparisons fail.
Summing many such values accumulates error, which matters for reconciliation, position keeping and anything compared against an exact expected figure.
The standard fix is to store amounts as integers in the smallest unit, or use a decimal type where the language provides one.
Where floating point is unavoidable, compare with a tolerance and sum with a compensated technique such as Kahan summation. Being able to name both the cause and two remedies is what is being checked.
What it is testing
Practical correctness habits from having shipped real systems.
Try these next
Maximum drawdown in one pass
Warm-upGiven an array of prices in time order, compute the maximum drawdown in a single pass.
Rolling median of a stream
HardMaintain the median of the last k values of a stream efficiently.
Design a limit order book
HardWhat data structures would you use for a limit order book that must add, cancel and match quickly?
Sample from a stream of unknown length
StandardPick one element uniformly at random from a stream whose length you do not know in advance, using constant memory.
Preparing properly
Live opportunities
Interviewing soon? See who is hiring
Open vacancies we track at quant firms, grouped by role and city. Adverts are anonymised.
Hiring for these roles? Brief the desk on a hire or check your fit for a role.
Research desk
Speak to a quant market specialist
Ask what a firm really pays, how a desk hires, or where your profile sits. One reply from the research desk, in confidence, no obligation.