Cache Shared Image Pipeline Prefixes
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:
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.
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
Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.