FastPrepCache Shared Image Pipeline Prefixes
Problems/Cache Shared Image Pipeline Prefixes

Cache Shared Image Pipeline Prefixes

Anthropic logoAnthropic● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in Anthropic full-time onsite interviews. The reports keep ordered image transforms and the reuse of cached in-between results across pipelines. They do not give an image model you can run, the exact meaning of each transform, how the output looks, or how to see what the cache did. We fixed those details and kept the same steps and state changes. Here you run a finite batch of pipelines.

An image is a grid of grayscale pixel values, with the same number of values in every row. Several pipelines all start from the same source image. Each pipeline is a list of transform names, applied in order.

Run every pipeline, but never compute the same partial result twice. A prefix of a pipeline is its first few transforms. After you apply a prefix, save the image you got under that exact prefix. If two pipelines start with the same prefix, compute that image only once and reuse it. The transforms are:

  • ROTATE_CW: turn the image 90 degrees clockwise.
  • FLIP_HORIZONTAL: reverse every row.
  • INVERT: change each pixel x to 255 - x.
  • ENLARGE_2X: replace each pixel with a 2 by 2 block of the same value.
  • SHRINK_2X: split the image into 2 by 2 blocks that do not overlap. Replace each block with one pixel: the average of its four values, rounded down.

Return a list of strings. The first string is steps=k, where k is how many different non-empty prefixes you actually computed. After that comes one string per pipeline, in pipeline order, showing its final image. Inside a row, separate pixels with commas. Separate rows with /. An empty pipeline returns the source image unchanged and adds no step.

Function

runCachedImagePipelines(image: int[][], pipelines: String[][]) → String[]

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"]
image
01012134

All three pipelines start with ROTATE_CW, so the rotated image is computed once. Rotating then inverting is a second prefix, and rotating then flipping is a third. The last pipeline is the same as the first, so it reuses the saved final image and adds nothing. Inverting the rotated image gives the first and last images, and flipping it gives the middle one. That makes three steps in total.

Example 2

image = [[0,255]]pipelines = [[],["INVERT"],["INVERT","INVERT"]]return = ["steps=2","0,255","255,0","0,255"]
image
0100255

The first pipeline is empty, so it returns the source image as it is and adds no step. The second pipeline inverts once, which swaps black and white. The third pipeline reuses that saved result and inverts it again, which gives back the source. Only two prefixes were computed, so there are two steps.

Example 3

image = [[10,20],[30,40]]pipelines = [["ENLARGE_2X","SHRINK_2X"],["ENLARGE_2X"]]return = ["steps=2","10,20/30,40","10,10,20,20/10,10,20,20/30,30,40,40/30,30,40,40"]
image
010102013040

Both pipelines start by enlarging, so the enlarged image is computed only once. In it, each pixel became a block of four equal values. Shrinking averages each block back to that one value, so the first pipeline gets the source image again. The second pipeline simply returns the saved enlarged image. That makes two steps in total.

Constraints

  • 1 <= image.length, image[i].length <= 40.
  • The image is rectangular, and every pixel is between 0 and 255.
  • 0 <= pipelines.length <= 1000, and each pipeline contains at most 20 transforms.
  • Every SHRINK_2X receives an image with even positive height and width.
  • Every intermediate image has at most 160000 pixels.

More Anthropic interview questions

  • Longest-Match Tokenizer with Unknown SymbolsONSITE INTERVIEW · Seen Oct 2026
  • Recover a Function-Call LRU Cache with a Write-Ahead LogONSITE INTERVIEW · Seen Oct 2026
  • Trace Events from Stable Whole-Stack StatesONSITE INTERVIEW · Seen Oct 2026
  • Confirmed Profiling Events with First-Observed StartsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Convert Stack Samples to Trace EventsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Profiling Events from Consecutive Stack SamplesPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Repair the Bootloader ProgramOA · ONSITE INTERVIEW · Seen Sep 2026
  • Fair Coin from a Biased CoinPHONE SCREEN · Seen Nov 2026
  • Crawl Same-Hostname URLs ConcurrentlyPHONE SCREEN · Seen Oct 2026
  • Find Duplicate File GroupsPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • First Completed Mingo LineEpic · OAEpic interview questions
  • Game of Life on a Finite and an Infinite BoardCitadel · PHONE SCREENCitadel interview questions
  • Sparse Plant Infection SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Randomized Collection with Duplicate ValuesOkta · ONSITE INTERVIEWOkta interview questions
  • Cats, Rabbits, and Snails Board GameAsana · ONSITE INTERVIEW
  • Transformer Attention and SwiGLU Forward PassGoogle · ONSITE INTERVIEWGoogle interview questions
  • Number of Submatrices That Sum to TargetWhatNot · ONSITE INTERVIEWWhatNot interview questions
  • Sustained Overspeed AlertsFleetx · ONSITE INTERVIEW
  • Spiral MatrixAthenahealth · ONSITE INTERVIEW
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions

Anthropic interview experiences

  • Anthropic PR Review Round with Claude Code: 2 Experiences
All Anthropic interview questionsSee Anthropic hiring insights
Saved
class Solution {
    public String[] runCachedImagePipelines(int[][] image, String[][] pipelines) {
      // write your code here
    }
}
Checking account…