Image pipeline
Anthropic candidates report an image round, with layers the interviewer adds one at a time (1 report). Others were asked to speed it up with processes, and why processes rather than threads (2 reports). It starts like this:
An image is a list of rows, and each row is a list of
(r, g, b)pixels from 0 to 255. A step is a tuple: a name, then its arguments, such as("grayscale",)or("rotate", 90).Write
apply(image, steps). Run the steps in order and return a new image, without changing the input. The steps aregrayscale, which makes each pixel(y, y, y)withy = (299 * r + 587 * g + 114 * b) // 1000,rotateby 90, 180 or 270 degrees clockwise,resize,crop, andmap, which runs a function on every pixel. Check every step before you run any, and raiseValueErrorfor a bad one.
Call, on the 1 by 2 image [[(255, 0, 0), (0, 0, 255)]]Returns apply(image, [("rotate", 90)])[[(255, 0, 0)], [(0, 0, 255)]]apply(image, [("grayscale",)])[[(76, 76, 76), (29, 29, 29)]]apply(image, [("spin", 1)])raises ValueError
Then the layers come: a batch of images where one bad image doesn't stop the others, then the batch on several threads, then one huge image split into bands and worked on in parallel. Each layer reuses the code before it, so your first version decides how hard the rest will be.
You don't write it yet. This lesson builds the same pattern on something smaller first, a table of sensor readings, and the practice problem at the end puts it back on images. At the end you solve the whole problem, level by level, in an interview simulation with a 60-minute timer.
Later it runs the work on a pool of threads, then adds processes: the same pool, used on work that keeps the CPU busy instead of work that waits.