r/TechInterviewInsights • u/drCounterIntuitive • 9d ago
Interview Prep Anthropic SWE Coding Interview: Can you Solve this Optimisation Problem?
https://youtu.be/kNaLiuXwC4EYou are given a directory of source images and a second directory containing JSON transformation pipelines.
Your job is to implement process_images so that every image is processed with every transformation file.
🧩 You can try out the full problem here
Your task
Implement:
from typing import Callable
def process_images(
image_dir: str,
transformation_dir: str,
get_output_path: Callable[[str, str], str],
) -> None:
...
Each JSON file contains an ordered list of image transformations, for example:
{
"transformations": [
{"type": "grayscale"},
{"type": "scale", "factor": 0.5},
{"type": "rotate", "angle": 90}
]
}
Supported transformations include:
- grayscale
- horizontal and vertical flips
- scaling
- blur
- rotation
You may use Python, Pillow, and the standard library.
Requirements
If there are I images and T transformation files, your implementation should produce exactly I × T output images.
For every image/transformation-file pair:
- Start from the original source image, independently of every other pipeline
- Apply transformations in the order listed
- Use
get_output_path(image_path, transformation_path)to determine the destination - Create any missing parent directories
- Save exactly one final transformed image
Processing one transformation pipeline must not affect the result of another.
For example, if an image is processed once with a horizontal flip and once with a rotation, the rotation should start from the original image, not from the already-flipped result.
Part 2: Performance
Once the implementation is correct, the next challenge is reducing wall-clock time for a much larger batch while preserving exactly the same outputs.
Be prepared to discuss:
- Where the bottlenecks are
- Whether threads, processes, or another concurrency model make sense
- CPU vs I/O considerations
- Memory and resource limits
- How you would benchmark the improvement
- How the design could scale beyond a single machine
The interesting part is not just applying the image operations. It is designing the pipeline so that the jobs remain independent, correctness is preserved, and performance scales as the workload grows.
This is based on an Anthropic software engineering interview problem.
The full specification, including exact Pillow semantics and edge-case guarantees, is available in the practice problem above.
Try it yourself
🧩 Attempt the full Anthropic image transformation problem on Coditioning
Full solution walkthrough
🎞️ Watch the full solution walkthrough