Opening coding question for quant developer roles.
Maximum drawdown in one pass
The question
Given an array of prices in time order, compute the maximum drawdown in a single pass.
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
Track the running maximum and the largest shortfall beneath it. O(n) time, O(1) space.
Walk the array keeping peak, the highest price seen so far, and worst, the largest value of (peak - price)/peak.
At each element, update peak first if the price is higher, otherwise update worst with the current shortfall.
Return worst at the end. One pass, constant memory.
Two details interviewers probe: whether you report drawdown as a fraction or an absolute amount, and what you return for an empty or single-element array. Say both out loud before writing.
What it is testing
Clean single-pass reasoning and edge-case discipline.
Try these next
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.
Why the loop order matters
StandardTwo implementations of matrix multiplication have identical complexity but one runs several times faster. Why?
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.