AlgoViz

Problem analyzer

medium 45 min

Eight questions that turn any prompt into a design skeleton in about six minutes: verbs, container, item, manager, policy, lifecycle, speed and sharing.

Video lesson · Chapter 1 of 6

Make a prediction

0:00 / 4:39

See it run

Eight questions, five prompts, and a new one down to running objects.

Operations

Parking lot

Fill the eight lines for: design a parking lot.

Step 1 of 6

Empty sheet

AnswerDecision
Verbs
Container
Item
Manager
Policy
Lifecycle
Speed
Sharing

Same eight lines as always.

Step 1: Empty sheet

for question in ["verbs", "container", "item", "manager",                 "policy", "lifecycle", "speed", "sharing"]:    answer = ask(question)    decide(answer)            # or: not needed
Heavy line
speed, sharing
First class
spots

Say the line before the step.

In the real world

The same problem analyzer doing real jobs. Pick one and step through it.

A substring search reads: design a phone address book.

Step 1 of 3

Look for one

  1. p
  2. h
  3. o
  4. n
  5. e
Singleton?

Found, inside phone.

Step 1: Look for one

Common mistakes

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

  • Pattern from a word

    critical

    The word may be inside another word, or mean something else.

    Wrong
    if "one" in prompt:    use("Singleton")
    Right
    if "single" in words(prompt):    ask("Would a second one be wrong?")
  • Filling every line

    major

    Invented managers and phases must be defended.

    Wrong
    class CacheManagerService:    def __init__(self, cache): ...
    Right
    # manager: none, the cache is enough
  • Storing what can be computed

    major

    It must be kept in step with every move.

    Wrong
    self.status = "check"
    Right
    def in_check(self, side):    return self.attacked(self.king(side))
  • A phase on the wrong object

    major

    One empty slot closes the whole machine.

    Wrong
    machine.state = SOLD_OUT
    Right
    if slot.count == 0:    show("SOLD OUT")
  • Rule between items inside an item

    critical

    A tablet cannot see the other tablets of a reader.

    Wrong
    class Tablet:    def lend(self, reader): ...
    Right
    class TabletDesk:    def lend(self, reader): ...

Interview tips

  • Aloud

    • Question.
    • Answer.
    • Decision.
  • Save time

    • None is an answer.
    • Values are not classes.
    • Find the heavy line.
  • Look back

    • Owner for every verb.
    • First and last phase.
    • Guard for every shared thing.
  • Do not

    • Recite letters.
    • Trust keywords.
    • Start with nouns.