Three hard problems the way a fintech interview frames them: fraud rings that only merge, the most money that survives a route, and a rate limiter for card swipes as a design round.
A fintech stretch round has one hard problem, or two in a long loop. The data structures are the ones from the core round, and the difficulty comes from rules that interact. A solution that is right for each rule alone can be wrong when they meet.
Three kinds of rule show up.
One problem in this set is a design round. You get a list of commands, such as swipe and count, and you answer each one in order. The state lives between commands, as it does inside a real service, and there is no class to write.
Exercise · Predict the output: A blocked swipe leaves no trace. One card may be swiped at most 2 times in any 10 seconds. A swipe at time t0 counts until t0 + 10. Swipes arrive at seconds 0, 3, 5, 9 and 10. How many are accepted?
times = [0, 3, 5, 9, 10]
limit = 2
window = 10
recent = []
accepted = 0
for now in times:
while recent and now - recent[0] >= window:
recent.pop(0)
if len(recent) < limit:
recent.append(now)
accepted += 1
print(accepted)The three problems use ideas from three Academy lessons. The new part is the rule you must not forget.
| Signal in the statement | The move | Academy lesson |
|---|---|---|
| groups that only merge, and the answer after every event | union-find with the size of each group | Union-find |
| each rail takes a share and a fee, and the most should arrive | always extend the hub that holds the most | Dijkstra's shortest paths |
| at most so many in the last seconds, for one card and for all | a queue of accepted times for each card and for everyone | Queue simulations and rounds |
Take the rings first. There are 6 accounts and 3 devices. The logins, as pairs of account and device, are (0, 0), (1, 0), (2, 1), (3, 1), (1, 1) and (4, 2). The largest ring after each login has 1, 2, 2, 2, 4 and 4 accounts.
If you count every node in the group, devices included, the answers are 2, 3, 3, 3, 6 and 6. A group of accounts and devices is not a ring of accounts.
Exercise · Predict the output: How many rings remain. Six accounts are joined by five links, in this order. How many separate groups remain at the end?
parent = list(range(6))
def find(x):
while parent[x] != x:
x = parent[x]
return x
for a, b in [(0, 1), (2, 3), (1, 3), (4, 5), (0, 2)]:
parent[find(a)] = find(b)
count = 0
for x in range(6):
if find(x) == x:
count += 1
print(count)Union-find with a size per group gives the largest ring after every login, counted in accounts.
The route problem has two details that the Academy lesson on Dijkstra does not need. A rail takes a share of the amount, rounded up, plus a fixed fee.
A route with fewer hops is not always better. With 1,000 units, a direct rail that takes 5% delivers 950. Two rails that take 0.5% and 10 units each deliver 970.
Exercise · Find the bug: The share rounds up. This follows a chain of rails and returns the units that arrive. Each rail takes a share in basis points, rounded up, plus a fixed fee. It is right whenever the share is a whole number of units. Which line is wrong?
def delivered(amount, rates, flats):
held = amount
for i in range(len(rates)):
fee = held * rates[i] // 10000 + flats[i]
held -= fee
return heldThe rate limiter is the design round of the set. Its two limits are checked together, and a swipe is accepted only when both have room.
A blocked swipe must leave no trace, or the card extends its own block.
All three are hard. The first two are graph problems and the last is a design round. Each time box is what a strong candidate needs, and a real loop would give you one of them.
Solve them in this order. The rings add a size to union-find, the routes add rounding to Dijkstra, and the rate limiter adds state that lives between commands.
A stretch problem is followed by a harder question. Prepare one for each.
The full set is 115 minutes, which is longer than any one interview. Use it as three separate sessions if you prefer, one problem each, with a timer.
For the design round, say aloud what each command reads and what it changes. A count reads and changes nothing, and a blocked swipe changes nothing too.
Checkpoint · Fintech stretch round
Q1/5 Accounts 0 and 1 log in from device 0. Nothing else has happened. What is the largest ring, counted as the problem asks?
Answer: B
The ring holds accounts 0 and 1. The device links them but is not an account, so a count of 3 nodes is wrong.
Q2/5 Why does union-find suit the fraud ring problem?
Answer: B
Every login can only join two groups. Union-find joins groups cheaply and cannot split them, which is enough when the groups only grow.
Q3/5 A rail takes 1% of 999 units, in basis points, rounded up, and no fixed fee. How many units arrive?
Answer: B
One per cent of 999 is 9.99, which rounds up to 10, so 989 arrive. Rounding down would let 990 arrive, and the rail would take less than its price.
Q4/5 Why can a route problem be solved by always extending the hub that holds the most money?
Answer: A
Money only shrinks along a route, so the hub with the most cannot be improved by a longer route. This is the property Dijkstra needs.
Q5/5 A card has used its limit, and a swipe is rejected. What does the limiter store about that swipe?
Answer: B
A blocked swipe leaves no trace. If its time were stored, a card that keeps trying would extend its own block for ever.
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.