Problem · Array

Cache Shared Image Pipeline Prefixes

HardAnthropic logoAnthropicFULLTIMEONSITE INTERVIEW

Problem statement

An image is a rectangular matrix of grayscale pixel values. Several requested transformation pipelines all start from the same source image. Each pipeline is an ordered list of transform names.

Execute the batch while caching every intermediate image by its complete transform prefix. If two pipelines share a prefix, compute that intermediate image only once. Supported transforms are:

The problem statement continues
Pro

Examples

Example 1

image = [[1,2],[3,4]]pipelines = [["ROTATE_CW","INVERT"],["ROTATE_CW","FLIP_HORIZONTAL"],["ROTATE_CW","INVERT"]]return = ["steps=3","252,254/251,253","1,3/2,4","252,254/251,253"]

The shared rotation, rotation-plus-inversion, and rotation-plus-flip are the three distinct non-empty prefixes. The repeated first pipeline reuses its cached final image.

FastPrep Pro
Reported in 1 Anthropic interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$9/month

Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Anthropic interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$9/month

Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week