Three easy problems the way a quant interview frames them: units that trade, the best single trade counted, and two moving averages compared exactly. A 55-minute round.
Quant and trading firms hire for strong maths and fast, careful code. Their coding interviews use ordinary data structures, but the problems come from markets: prices in a series, offers to buy and to sell, averages over a window. The interviewer talks with you throughout and often asks you to defend your answer.
Four habits matter most.
The warm-up round tests these habits on three easy problems. It is the first of two rounds in the quant set: the second round holds the harder problems of heaps, drawdowns and probability, and uses the same habits.
Exercise · Predict the output: Ways to make the best trade. A trade buys on one day and sells on a later day. The prices are 3, 1, 1, 6 and 6. The best profit is 5. How many pairs of days make that profit?
prices = [3, 1, 1, 6, 6]
best = prices[1] - prices[0]
lowest = prices[0]
for day in range(1, len(prices)):
best = max(best, prices[day] - lowest)
lowest = min(lowest, prices[day])
seen = {}
ways = 0
for price in prices:
ways += seen.get(price - best, 0)
seen[price] = seen.get(price, 0) + 1
print(ways)Each problem is easy because the Academy already taught the idea. The quant frame adds the exactness and the counting.
| Signal in the statement | The move | Academy lesson |
|---|---|---|
| units trade at one item and one price, buys against sells | a map from the key to two totals, then the smaller total | Counting and grouping |
| the best profit, and how many ways | the lowest earlier price, then a map of earlier prices | Running balances and two passes |
| one average above another, exactly | window sums from prefix sums, compared by multiplying out | Sliding window: fixed and variable windows and Prefix sums in 1D and 2D |
The matching problem has a trap in the frame. The units that trade are the smaller of the two totals at each item and price, summed over all keys. Taking the smaller of the two grand totals ignores the keys, and an offer at one price cannot trade with an offer at another.
The averages problem has the exactness trap. The two averages are fractions, and the statement says equal averages do not count. Dividing with whole numbers floors both, and two different averages can floor to the same value.
Exercise · Find the bug: Averages that round. This counts the days on which the fast average is strictly above the slow average, using prefix sums. It misses days where the two averages differ by less than one unit. Which line is wrong?
def count_fast_above_slow(prices, fast, slow):
prefix = [0] * (len(prices) + 1)
for i in range(len(prices)):
prefix[i + 1] = prefix[i] + prices[i]
days = 0
for day in range(slow - 1, len(prices)):
fast_sum = prefix[day + 1] - prefix[day + 1 - fast]
slow_sum = prefix[day + 1] - prefix[day + 1 - slow]
if fast_sum // fast > slow_sum // slow:
days += 1
return daysDividing whole numbers floors both averages, so a real difference vanishes; multiplying out keeps it.
The counting follow-up is where a quant interviewer leans in. The best profit comes from a lowest price, but several days can share it, and several later days can share the best sale price. The number of ways is the number of pairs, so a single running minimum cannot count it, and a map of earlier prices can.
The number of ways is the number of pairs: each low day pairs with each later high day.
Exercise · Predict the output: Units that trade. Offers are given as item, price, side and quantity. Side 0 buys and side 1 sells. The offers are (1, 5, buy, 10), (1, 5, sell, 4), (1, 5, sell, 9), (2, 5, buy, 3) and (1, 6, sell, 2). How many units trade in total?
items = [1, 1, 1, 2, 1]
prices = [5, 5, 5, 5, 6]
sides = [0, 1, 1, 0, 1]
quantities = [10, 4, 9, 3, 2]
totals = {}
for i in range(len(items)):
key = items[i] * 1000 + prices[i]
if key not in totals:
totals[key] = [0, 0]
totals[key][sides[i]] += quantities[i]
traded = 0
for buy, sell in totals.values():
traded += min(buy, sell)
print(traded)All three are easy, and together they are a standard quant warm-up. Each time box includes saying the complexity aloud before you start to code.
Solve them in this order. The matching report is a map and a minimum, the best trade adds a counting pass, and the averages add exact comparison.
Quant interviewers change one rule and ask what it costs. Prepare one change for each problem.
Treat the three problems as one interview: 55 minutes in all, with a timer, speaking as if the interviewer were listening.
If a problem runs over its box, finish it and note the overrun. In a real interview the interviewer would have moved on, so your next attempt should be quicker.
Checkpoint · Quant warm-up round
Q1/5 Which of these does a quant interviewer expect you to state before you write the code?
Answer: B
Stating the complexity first shows that you know what the problem needs. It also gives the interviewer something to challenge.
Q2/5 Offers at one item and price add up to 10 units to buy and 13 units to sell. How many units trade at that key?
Answer: B
Units trade up to what both sides can supply, which is the smaller total. The answer is 10.
Q3/5 The prices are 3, 1, 1, 6 and 6, and the best profit is 5. How many pairs of days reach it?
Answer: C
Two low days pair with two later high days, giving 2 times 2 pairs. One running minimum would see only one of them.
Q4/5 Two moving averages are 3.5 and 3.33. Why do whole-number divisions compare them wrongly?
Answer: B
Flooring removes the fractions that decide the comparison. Multiplying out compares the true values with whole numbers only.
Q5/5 The fast window has 2 prices that sum to 7, and the slow window has 3 prices that sum to 10. Which test is correct for the fast average being strictly above the slow one?
Answer: B
The test 7 times 3 against 10 times 2 compares 3.5 with 3.33 exactly, and 21 is greater than 20. The floored test compares 3 with 3 and fails.
Review cards from this lesson.
A few questions, then explain the idea back in your own words. Your tutor marks it. Quiz and explain back.