Generate outputs for images and pipelines
Company: Anthropic
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates algorithmic and systems engineering skills related to batch image processing, parallelization, I/O versus CPU trade-offs, and deterministic output association within the Coding & Algorithms domain.
Constraints
- 0 <= len(image_paths), len(pipelines)
- A pipeline may be empty
- All paths in `image_paths` exist in `image_store`
- The total number of operations across all pipelines is at most 2 * 10^5
- The returned list has exactly `len(image_paths) * len(pipelines)` entries, so any solution must spend at least O(m*n) time to build the output
Examples
Input: (['a.png', 'b.png'], {'a.png': 2, 'b.png': 5}, [[('ADD', 3), ('MUL', 2)], [('NEG',), ('SUB', 4)]], 'out')
Expected Output: [('out/img0_pipe0.png', 10), ('out/img0_pipe1.png', -6), ('out/img1_pipe0.png', 16), ('out/img1_pipe1.png', -9)]
Input: (['x', 'x', 'y'], {'x': -3, 'y': 0}, [[], [('MUL', -1), ('ADD', 2)], [('SUB', 5), ('NEG',)]], 'res')
Expected Output: [('res/img0_pipe0.png', -3), ('res/img0_pipe1.png', 5), ('res/img0_pipe2.png', 8), ('res/img1_pipe0.png', -3), ('res/img1_pipe1.png', 5), ('res/img1_pipe2.png', 8), ('res/img2_pipe0.png', 0), ('res/img2_pipe1.png', 2), ('res/img2_pipe2.png', 5)]
Hints
- Each supported operation keeps the form `a*x + b`. Try compressing each whole pipeline into one pair `(a, b)` before processing the images.
- If the same path appears more than once in `image_paths`, cache its loaded value so you do not conceptually decode it multiple times.