Five small product features, built the way a startup interview asks: clean signups, a search index, a setup checklist, an expiring cache and a pricing formula. A 120-minute round.
A startup has a small team and a product that changes every month, and its interviews reflect that. You are not given a puzzle from a book. You are given a small feature close to the product, such as a search box or a cache. You build it while an engineer from the team plays a colleague.
The interviewer listens for four habits.
This round is the whole startup set in one session. Startup sets are small, with five problems in total, so one round holds an easy problem, two medium ones and two hard ones, in that order.
Exercise · Predict the output: Setup rounds with a cap. Five checklist steps are numbered 0 to 4. Step 3 needs steps 0 and 1, and step 4 needs step 2. Each round takes at most 2 ready steps, smallest first, and a round finishes before its steps unlock others. In which round is step 4 taken?
n = 5
needs = [[3, 0], [3, 1], [4, 2]]
cap = 2
unmet = [0] * n
for a, b in needs:
unmet[a] += 1
taken = [False] * n
rounds = [0] * n
left = n
r = 0
while left > 0:
r += 1
batch = []
for step in range(n):
if not taken[step] and unmet[step] == 0 and len(batch) < cap:
batch.append(step)
for step in batch:
taken[step] = True
rounds[step] = r
left -= 1
for step in batch:
for a, b in needs:
if b == step:
unmet[a] -= 1
print(rounds[4])A round takes up to the cap of ready steps, smallest first, and its steps unlock others only afterwards.
Each feature below is small, and each maps to one Academy lesson. What the startup frame adds is the product question that hides the edge case.
| Signal in the statement | The move | Academy lesson |
|---|---|---|
| one account for each person, however it was typed | a normal form as the key, and a seen-set | Seen-set and complement |
| a suggestion for what is typed so far, with growing weights | a trie that stores the best word at every node | Tries |
| steps that need other steps, and a cap for each round | in-degree counts and a min-heap of ready steps | Topological sort |
| a cache with a size limit and an age limit | an ordered map for recency and a queue of expiry times | Doubly linked lists and the LRU cache |
| a formula with brackets and functions | two stacks, one for values and one for operators | Parsing and expression evaluation |
The cache is the feature where a product question matters most. When does an entry stop being alive: at the instant its age reaches the limit, or after? The statement says an entry written at time w is expired when w + ttl <= now. At the exact boundary the entry is already gone, and a comparison that is off by one keeps it.
Exercise · Find the bug: The instant an entry expires. An entry written at time w with lifetime ttl expires at time w + ttl, and is gone at that instant. This counts the live entries at time now. It is right except at the boundary. Which line is wrong?
def live_count(write_times, ttl, now):
live = 0
for written in write_times:
if written + ttl >= now:
live += 1
return liveAn entry expires at the instant its age equals the lifetime; a greater-or-equal test keeps it too long.
The signup list is the easy problem, and it hides a trap that startup teams meet in real data. Many mail services ignore capitals, ignore dots and ignore a tag after a plus sign, but only in the part before the @. Dots in the domain are part of the address.
Exercise · Break it: Dots in the domain. This keeps the first address of each person. It cuts the tag after a plus sign and removes dots, but from the whole address. Find lists where two different people are merged.
def unique_signups(emails):
seen = set()
kept = []
for email in emails:
at = email.index("@")
local = email[:at]
plus = local.find("+")
if plus != -1:
local = local[:plus]
key = (local + email[at:]).replace(".", "").lower()
if key not in seen:
seen.add(key)
kept.append(email)
return keptThe search index, the checklist and the formula follow the same pattern. The Academy lesson gives the method, and the statement adds a rule that decides the hidden cases. The checklist breaks ties by the smallest step number, the index by the alphabet, and the formula cuts division towards zero.
The ladder rises from an easy problem to two hard ones. In a real startup session you would meet one or two of them, so treat the later problems as the extended version of the round.
Solve them in this order. The signup list is one map and the index adds a tree of letters. The checklist adds a heap, the cache joins an ordered map with a queue, and the formula uses two stacks.
After a working version, a startup interviewer changes a rule. Prepare one change for each problem.
The whole set is one long session: 120 minutes in all. Split it into two sittings of 60 minutes with a break, and work as if a teammate sits beside you.
If the hard problems run over their boxes, finish them anyway and note the overrun. The time box for each problem is on the ladder: 15, 20, 25, 30 and 30 minutes.
Checkpoint · Startup full round
Q1/5 A startup interviewer gives you a short statement for a search feature. What is the best first move?
Answer: B
The statement is short on purpose. Questions show that you care about the product, and the answers decide the edge cases.
Q2/5 What is the normal form of Ann.Lee+news@Mail.com, when the part before the @ ignores case, dots and a tag after a plus sign?
Answer: B
The tag after the plus sign is cut and the dots before the @ are removed, then everything is lower case. The domain keeps its dots.
Q3/5 The addresses ann@a.bc and ann@ab.c reach different inboxes. Why must the key keep the dots of the domain?
Answer: C
Removing dots from the whole address would make the two domains equal. The two addresses belong to different people.
Q4/5 An entry is written at time 0 with a lifetime of 5. Is it alive at time 5?
Answer: B
The entry is alive for times 0 to 4. At time 5 its age equals its lifetime, so it is already gone.
Q5/5 Steps 0, 1 and 2 are ready and the cap is 2 for each round. Which steps does the first round take?
Answer: B
The cap allows two steps, and ties go to the smallest numbers. Step 2 waits for the next round.
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.