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

See it run

The same two calls, sell and redeem. Each level answers one more question.

Operations

Junior: it works

Eleven drinks, one free drink, one stamp left. Then somebody else writes the field.

Step 1 of 5

Ten drinks later

tillTilladminAdminScreensam's cardCardstamps10

The till called buy ten times.

Step 1: Ten drinks later

def buy(self):    self.stamps += 1def redeem(self):    if self.stamps >= 10:        self.stamps -= 10        return True    return False
Question
does it work?
Adds
a counter

Trace with eleven, not ten.

In the real world

The same one stamp card, four levels doing real jobs. Pick one and step through it.

Sam used ten stamps, then gives back six drinks.

Step 1 of 4

Twelve stamps

tillTillloyaltyLoyaltybalance12sam's ledgerLedgerentry 1a, +6entry 2b, +6

Two sales of six.

Step 1: Twelve stamps

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Reset to zero

    major

    The eleventh stamp is lost.

    Wrong
    if self.stamps >= 10:    self.stamps = 0
    Right
    if self.stamps >= 10:    self.stamps -= 10
  • Check outside the lock

    critical

    Two tills pass the check together.

    Wrong
    if ledger.balance() >= goal:    with ledger.lock:        ledger.record(entry)
    Right
    with ledger.lock:    if ledger.balance() >= goal:        ledger.record(entry)
  • A sale without a name

    critical

    A retry looks like a new sale.

    Wrong
    shop.sell("sam", 1)
    Right
    shop.sell("sam", receipt, 1)
  • Reading the real date inside

    major

    The test would have to wait.

    Wrong
    day = date.today()
    Right
    day = self._today()      # handed in
  • Editing history

    major

    Afterwards nobody can explain the balance.

    Wrong
    entry.stamps = 0
    Right
    ledger.record(Entry("x", "refund", -6, day))

Interview tips

  • Before you start

    • Ask which level.
    • Core in 15 minutes.
    • Say what you leave out.
  • To look senior

    • Name two failures yourself.
    • Put the check inside.
    • Test the retry.
  • To look staff

    • Cost of a mistake.
    • Speed of change.
    • The smaller design.
  • What lowers you

    • Castles.
    • Silence.
    • Defending a mistake.