Practice problem · Pinterest · Medium

Read-Through Cache for the Pin Service

The pin service answers reads for pins (an image saved to a board) and boards. 4 stages in Python with an AI assistant. Pro.

Stage 1 of 4: Cache the pins

Background. The pin service answers reads for pins (an image saved to a board) and boards. Reads go to a store that is slow in production; BoardService in services.py already serves boards through a cache, and the other modules (read_through.py, policies.py, store.py, models.py) are what it is built from. PinService still reads the store on every call.

Serve PinService.get_pin through a cache of cache_size pins, the way boards are served.

Done when Submit goes green.

Constraints

  • Python 3.12+ standard library only
  • Time limit: 10 seconds per test file
  • Editable: services.py, lfu.py
  • Read-only: read_through.py, policies.py, store.py, models.py, test_helpers.py, all tests/test_*.py files

What comes after stage 1

The next stages open once the tests for the one before them pass. Each raises the bar, the way an interviewer does in the room.

  1. Stage 2: Writes and listings. Pins change and boards never did; a second cached view has to stay right across every write.
  2. Stage 3: A second policy. Keep the popular pins: a policy that counts, with a tie rule to get right.
  3. Stage 4: Under load. Hundreds of thousands of reads, about half of them misses, and every miss evicts.

The files you get

  • Yours to edit: services.py, lfu.py.
  • Read-only: read_through.py, policies.py, store.py, models.py, test_helpers.py, tests/__init__.py.
  • Tests you can read and run: tests/test_part1_pin_reads.py. Hidden tests run on Submit.

The round: an agent in the editor

The assistant here works like the one in the interview IDE. It reads your files, runs code and proposes changes, and you accept or reject each one. It doesn't volunteer ideas, so what gets built is what you asked for. Along the way the interviewer asks about your decisions, and at the end the report says what you checked and what you accepted unread.

Frequently asked, briefly answered

Is Read-Through Cache for the Pin Service free?

It is a Pro problem. Free plan includes one complete problem, plus the first stage of several more, so you can see how a round works before you pay.

Which company asks something like this?

Pinterest. It is modelled on Pinterest's round: Virtual onsite AI coding round (45 minutes): a project repository with a task about caching, an AI assistant the candidate directs, graded on understanding the code across files, testing, and explaining the approach; described by a recruiter as experimental.

Do I bring my own AI tool?

No. The assistant is in the editor, same as in the interview IDEs at Meta, Stripe and Amazon. What you choose at Begin is the format: an agent that proposes changes you accept or reject, an answer-only assistant that can't write code, or no assistant at all.

What does the interviewer ask?

3 questions along the way about your own code, and one at the end about the whole session. A weak answer gets one follow up. The answers go into the report, which ends with a hire or no hire verdict.

Start the problem

Sign in and the problem opens where you left it. New here? An account takes a minute to create, and the Pro plan starts at the first stage of this problem.

Start this problem → Sign in

More like it: every practice problem, how Pinterest runs its AI round, the AI coding interview guide.