Opening coding question for quant developer roles.

Maximum drawdown in one pass

Warm-up

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

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.