AlgoViz

Junior, mid and senior answers

medium 45 min

The same prompt is given to people with two and with twelve years behind them.

Video lesson · Chapter 1 of 6

Make a prediction

0:00 / 4:58

Junior, mid and senior answers

1:02Reel

Theory

Read or listen first. About 2 min.

What it is

A design round is usually the same prompt for every level. A parking lot, a card, an elevator. The interviewer does not ask a harder question to a senior person. They listen for different things in the answer.

Levels are best seen as questions that a person asks without being told. Junior: does it work? Mid: does it stay correct when used in a way I did not plan? Senior: what happens when something fails or when two things happen at once? Staff: is this the right thing, and how does it change over years?

Each level contains the one before it. A staff answer that does not run is not a staff answer. This is why the code on this page grows: nothing is thrown away.

Why it exists

Many people prepare one level too high or too low. A junior who talks about distributed locks and has no working code loses both. A senior who stops at clean classes looks like a mid.

It helps to know what is not expected of you. Time is fixed at about 45 minutes. Depth in the things of your level beats a list of words from the next one.

And it gives you a way to grow. The gap between two levels is a small set of habits that you can practise on any problem.

A short history

  1. 1980

    Stuart and Hubert Dreyfus describe five stages of learning a skill in a report at Berkeley. Beginners follow rules, experts see what matters in the situation.

  2. 2018

    CircleCI rebuilds its engineering competency matrix, three years after its first one, and publishes how it was done.

  3. 2023

    Dropbox publishes an update of its engineering career framework and explains why it was changed.

Words to know

Level
How much uncertainty a person handles alone. Titles differ between companies.
Signal
Something you said or wrote that an interviewer can note down.
Scope
How far your care reaches: a method, a class, a service, years.
Edge case
An input at the border of what is allowed.
Failure case
Something outside your code goes wrong: a retry, a crash, a second thread.
Ledger
A list of facts that is only added to. The balance is computed from it.
Idempotent
Doing it twice has the same effect as doing it once.
Trade-off
A choice with its price said aloud.
Leveling down
Being offered a lower level than the one you applied for.

How it works

Step through the idea, or press Play.

Step 1 of 4

Junior. Does it work?

Understand it

Start here

Four builders repair one fence

Sam's fence has three broken boards. Sam asks four builders, on four different days, with the same sentence: please repair my fence.

Sam's fence
Please repairmy fence

Boards, gate, post, steps. Works, usable, solid, right.

The map

What each level shows

Same 45 minutes, different signals

Part of the roundJuniorMidSeniorStaff
QuestionsWhat should it do?Limits, wrong input, who uses itHow often, how many at once, what must never happenWhy do we need it, who pays for mistakes, what comes next year
EntitiesThe nouns of the promptRejects some, gives each rule an ownerSeparates facts from computed valuesSeparates what changes at different speeds
CodeRuns, good namesPrivate state, checks before changesAtomic steps, time handed in, tests for failureSmall contracts, versions, room to remove
ErrorsOne checkRefuses with a reasonRetries, partial failure, idempotencyLimits the damage, plans repair
TestsHappy path by handBordersRace, retry, clockOld and new rule side by side
ExtensionCan do it when told howShows the one placeShows the costSays whether to do it at all
TalkExplains whatExplains whyExplains why notExplains what would change the decision
Read a column downwards to prepare for your level. Read one to the right to see what stands out.

Where to spend the minutes

Nobody skips the first box. Higher levels get through it faster.

The prompt

A stamp card for a coffee shop

The prompt: design a loyalty card. A customer gets a stamp for each drink. Ten stamps give a free drink. It is small enough to write four times, and deep enough to show all four levels. Before you read on, spend two minutes on your own questions.

Questions the four people ask

LevelFirst questionsWhat the answers change
JuniorOne stamp per drink? Exactly ten?Two numbers in the code
MidCan a free drink earn a stamp? May one card be used in two shops? What if someone redeems with nine?A rule object, a map of cards, clear refusals
SeniorWhat if the till sends the same sale twice? Two tills with one card? Refunds? Do stamps expire?Receipt ids, a ledger, a lock, a clock
StaffWhy do we give free drinks? What if marketing changes ten to eight next month? Who loses when a bug gives away drinks?Dated rules, a limit, a way to compare old and new, and perhaps a smaller design

Level 1

The junior answer

It works, it is short, and it can be read by anybody. That is a good answer. Its weakness: everybody can write stamps, and the number ten appears where it is used.

Junior: one class, open to everybody

buy()Card+ stamps: int+ buy()+ redeem(): boolTill+ sell(card)

1/2The asked thing

A till calls buy, the card counts, redeem gives a free drink at ten.

uses

Right for day one. It has no defence.

Level 2

The mid answer

Nothing new is promised to the customer. What changes is who may touch what: the number is private, the rule has a name, and callers go through one door.

Mid: each rule has an owner

refuses withCard- stamps: int+ add(n)+ use(n)NotEnoughStampshave, need: int

1/3The card guards its number

Private stamps, two methods, and no way below zero.

owns (dies together)usesdepends on

From junior to mid

Eight lines that do what was asked. Write this first at every level.

class SimpleCard:    def __init__(self):        self.stamps = 0    def buy(self):        self.stamps += 1    def redeem(self):        if self.stamps >= 10:            self.stamps -= 10            return True        return Falsecard = SimpleCard()for _ in range(11):    card.buy()assert card.redeem() and card.stamps == 1assert not card.redeem()

Lines 9 to 11

Subtract ten, do not set to zero. With eleven stamps the customer keeps one. Many first versions lose it.

1 of 3

Why it is built this way

  • Saying this is version one, it works, now I make it safe is a sentence of a good junior.

Level 3

The senior answer

The senior person writes the mid version quickly, and then breaks it. The till's network drops after the sale was counted, so it sends the sale again. The customer stands at two tills of one shop. A drink is returned. The number on the card cannot answer any of these, because it has forgotten where it came from.

The retry that gives two stamps

Nothing is wrong with the classes. The design lacks a name for the sale.

Senior and staff: facts, rules and one gate

Ledger- entries: List<Entry>- seen: Map<receipt, Entry>+ balance(): int+ find(receipt): Entry+ record(entry)Entryreceipt, kind: Stringstamps: int, day: Day

1/4Facts instead of a number

The ledger keeps entries and never changes one. The balance is their sum, so it can always be explained.

owns (dies together)useshas (lives on)

The card from the mid version became a ledger. The calls stayed, with a receipt added. Refunds are written out in the Code tab.

From senior to staff

Each change is an entry with the receipt that caused it.

import threadingfrom dataclasses import dataclass@dataclass(frozen=True)class Entry:    receipt: str    kind: str    stamps: int    day: intclass Ledger:    def __init__(self):        self._entries = []        self._seen = {}        self.lock = threading.Lock()    def balance(self):        return sum(e.stamps for e in self._entries)    def find(self, receipt):        return self._seen.get(receipt)    def record(self, entry):        self._entries.append(entry)        self._seen[entry.receipt] = entry

Lines 5 to 10

Frozen. A fact that can be edited is not a fact, and then nobody can explain the balance to a customer.

1 of 4

Level 4

What staff adds without code

A staff answer is often shorter in code and longer in judgement. Here are things a staff candidate would say about the card, and each of them is a decision.

Five staff sentences

  • Is it needed?

    A paper card costs almost nothing. The program is worth building if we want to know who comes back.

  • What is a mistake worth?

    A wrong free drink costs little. So I prefer to give one too many over making a queue wait.

  • What changes at which speed?

    Rules monthly, receipts never, card identity rarely. So these live in three places.

  • How do we switch?

    Run the new rule beside the old one for a week and compare the numbers before it counts.

  • What do we leave out?

    No expiry in the first version. The ledger has the days, so it can be added without moving data.

Staff: changing the rule safely

One question, four answers

What happens if the same card is used at two tills?

The same follow-up, four times

  1. Interviewer

    The same card is used at two tills at the same moment. What happens?

  2. You

    Junior: Both call redeem. I think both could get a drink. I would need to make sure that only one can do it at a time, with a lock.

  3. You

    Mid: The check and the subtraction must be one step. I put a lock around use in the card, so the second till gets NotEnoughStamps.

  4. You

    Senior: I lock per card and not per shop, I keep the check inside, and I test with eight threads. Across servers I use a unique receipt and a conditional update, because a lock in memory does not reach that far.

  5. You

    Staff: First I ask what it costs if it goes wrong: one drink. In one process the lock is simple, so I take it. Across shops I would accept a rare second drink, count such cases, and spend the effort elsewhere.

The interviewer says: now stamps should expire after a year. What do you do?

BreaksReset stamps to zero each January
How
One job sets the number.
Limit
A stamp from December lives one month. And the number cannot say how old each stamp is.
Choose when
Never, unless that is the rule people were told.
WorksStore a date next to the number
How
The last purchase date decides.
Limit
One purchase keeps all old stamps alive. Perhaps wanted, but then say it.
Choose when
If the rule is: one year without a visit.
StrongCompute from the ledger
How
Entries have days. Spend the oldest stamps first, and count only those younger than a year.
Limit
The balance costs a walk through the entries, or a small queue of open lots.
Choose when
When each stamp has its own age. The ledger makes it an addition.

Traps

How people miss their level

Signals that pull you down, and the repair

What happensHeard asDo instead
Talks about scale, no running classJunior or less, whatever the wordsCore first, in 15 minutes
Patterns by name, no forceMid at bestForce, pattern, cost
Clean code, waits to be asked about failureMidName two failures before the interviewer does
Every failure handled, nothing finishedSenior without judgementPick the two that cost most
Agrees with every suggestionUnsureGive the trade-off, then decide
Defends a mistakeHard to work withSay: you are right, here is the smallest change

Grows your level

  • One sentence before each step: what I do and why
  • Numbers in the trace
  • Naming what you leave out, and why
  • Changing your mind with a reason

Lowers your level

  • Silence for five minutes
  • Words without code
  • Building for a future nobody mentioned
  • Asking permission for each line

Which level did I just show?

Use it after each practice round.

Practice

Climb one level in two weeks

A plan that fits any problem

  1. 1

    Solve it at your level

    45 minutes, with a timer, aloud. Keep the code.

  2. 2

    Ask the four questions

    Works? Stays correct? Fails how? Right at all? Write down the first one you did not ask.

  3. 3

    Add one level only

    Change the same code. Do not start again.

  4. 4

    Write the test first

    The retry, the race, the new rule. If it passes already, you were higher than you thought.

  5. 5

    Say it in two sentences

    What I added, and what it costs.

Useful next pages: verifying and extending a design, concurrency in LLD for the senior step, and YAGNI for the staff step.

Summary

The whole topic in one minute.

Junior makes it work and reads well. Mid protects it from wrong use and puts each rule in its place. Senior adds failure, time and concurrency, with tests that prove it. Staff questions the prompt, plans change over years and removes what is not needed.

Every level contains the previous one. Show yours by the questions you ask without help.

Titles vary between companies, and so do expectations. Ask your recruiter which level the round is for.

  • Same prompt, different questions asked without help.
  • Every level contains the one before.
  • Junior: it works. Mid: it stays correct. Senior: it survives. Staff: it is right.
  • Subtract ten, do not reset to zero.
  • Give facts names: receipts make retries safe.
  • Say the cost of a mistake before you fix it.
  • A castle on paper does not repair a fence.

Sources