Three medium problems the way a SaaS interview frames them: usage quotas over rolling windows, effective permissions in a folder tree, and audit events confirmed by enough shards. An 80-minute round with a plan.
The warm-up round of this set checked the tenant in the key, repeated events, the peak and quiet days. The core round keeps those habits and adds medium problems about limits, hierarchies and logs. The interviewer listens for four new habits.
The core round has three medium problems: usage quotas over rolling windows, effective permissions in a folder tree, and audit events confirmed by enough shards. Together they take about an hour and a half.
This is the second of three rounds in the SaaS set. Warm up first with the warm-up round if keys, repeats and cutoffs still feel slow.
Exercise · Predict the output: Events with enough shards. Three shards hold sorted event numbers. An event is confirmed when it appears on at least 2 different shards. What does this print: the confirmed events in increasing order?
shards = [[1, 3, 5], [1, 2, 5], [2, 5, 9]]
quorum = 2
counts = {}
for shard in shards:
for event in shard:
counts[event] = counts.get(event, 0) + 1
print(*sorted(e for e in counts if counts[e] >= quorum))Each problem names its move in the statement. Read the signal, then use the idea the Academy already taught you.
| Signal in the statement | The move | Academy lesson |
|---|---|---|
| a quota over the last minute and the last hour, rejected requests use nothing | two window totals with pointers that only move forward, fed by accepted requests | Fixed and variable windows |
| a value inherited from the parent, changed by each node | pass the parent's result down the tree, once for each node | Tree recursion: heights, diameters and paths |
| several sorted logs, an event on many shards, a quorum | a heap of the front of each shard, counting equal values as they come out | Top k and k-way merge |
What is new here is the frame, not the idea. The window holds accepted requests only, so a rejected request is never added. The tree is given as a parent array, so it can be very deep, and a recursive walk may overflow the stack. And equal events come out of the merge next to each other, so a run of equal values is a count.
The folder problem has an order of operations that decides the answer. A folder adds its grants first and then removes its revokes, so a bit that is in both is removed.
Exercise · Put it in order: Permissions on one folder. Arrange the lines into a function that returns the permissions in effect on one folder. The root starts with none. Each folder on the way down first adds its grant bits, then removes its revoke bits, so a bit in both is removed.
def effective(parent, grant, revoke, node):
path = []
while node != -1:
path.append(node)
node = parent[node]
bits = 0
for n in reversed(path):
bits = (bits | grant[n]) & ~revoke[n]
return bits
bits = (bits & ~revoke[n]) | grant[n]A folder adds its grants first and removes its revokes second, so a bit in both is removed.
The quota problem has a mistake that looks like a harmless shortcut. The window must hold accepted requests only.
Exercise · Break it: A rejected request that uses quota. Requests arrive in time order, each with a cost. A request is accepted when the cost already used in the last 60 seconds plus its own is at most the limit. Rejected requests must use nothing. This one adds every request to the window. Find an input where it rejects a request it should accept.
def allowed_requests(times, costs, limit):
window = []
first = 0
total = 0
answers = []
for i in range(len(times)):
while first < len(window) and times[i] - times[window[first]] >= 60:
total -= costs[window[first]]
first += 1
ok = total + costs[i] <= limit
window.append(i)
total += costs[i]
answers.append(1 if ok else 0)
return answersA rejected request uses no quota: adding it to the window makes later requests fail.
All three problems are medium, and together they make one core round. Each time box is close to what an interviewer allows for a medium problem, with time to explain.
Solve them in this order. The first slides two windows at once, the second passes a value down a tree, and the third merges sorted logs with a count.
Core problems invite a bigger follow-up. The interviewer changes one rule and asks whether your idea still holds. Prepare one for each problem.
Treat the three problems as one session: 80 minutes in all, with a timer. Work out loud, and say the cost of each step as you go.
If a problem takes longer than its box, finish it anyway, but note the overrun.
Checkpoint · SaaS core round
Q1/5 The limit is 10. Requests cost 6, 6 and 3 within one minute. Which are accepted?
Answer: B
The first uses 6. The second would make 12, so it is rejected and uses nothing. The third fits: 6 + 3 = 9.
Q2/5 A quota has a minute limit and an hour limit. When is a request accepted?
Answer: B
Both limits must hold, so a request needs room in the minute window and in the hour window.
Q3/5 A folder grants bits 5 and revokes bits 4 on top of an empty parent. Which bits are in effect?
Answer: B
The grant adds bits 4 and 1, and the revoke removes bit 4, so only bit 1 remains. The revoke wins.
Q4/5 A folder tree is one chain of 100,000 folders. Why avoid a recursive walk?
Answer: B
The recursion would be 100,000 calls deep, which can overflow the stack. Process the folders in order from the root instead.
Q5/5 Shards hold 1 3 5, 1 2 5 and 2 5 9, and the quorum is 2. Which events are confirmed?
Answer: B
Events 1, 2 and 5 each appear on at least 2 shards. Events 3 and 9 appear on one shard only.
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.