← Questions

Image transform pipeline with a wall-clock budget

0
AnthropicCodingLast asked Oct 2026

Apply a fixed sequence of image transforms (grayscale, flip, scale, blur, rotate) to every image in a directory, then speed the batch up with threads or processes to hit a wall-clock target. Expect questions about what parallelizes and what does not.

Images here are lists of rows of (r, g, b) tuples, so the code runs anywhere.

def grayscale(img): ...
def flip(img): ...            # mirror left to right
def scale(img, factor): ...   # nearest neighbour
def blur(img): ...            # 3x3 box blur, edges clamped
def rotate(img): ...          # 90 degrees clockwise


def apply_steps(img, steps=None):
    """Apply [(name, kwargs), ...]; default: grayscale, flip, scale 0.5, blur, rotate."""


def run_batch(images, steps=None, budget_s=None, mode="process", workers=4):
    """{name: image} -> (results, sorted skipped names); mode is serial, thread or process."""
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding