The interview problem

Practice prompt

Build on-device portrait background replacement that handles hair, moving hands and low light while meeting a 30-frame-per-second rendering budget.

Original practice, not a reported company interview. All scenarios and worked numbers are illustrative. Interview date: not applicable. Sources retrieved September 30, 2026.

1. Scope and assumptions

Predict an alpha matte between zero and one, not merely a binary person mask. Assume the user enables the feature; keep a bypass mode for unsupported devices or poor confidence.

2. Worked approach

camera frame
  → alpha prediction
  → motion-aware stabilization
  → compositing
  → frame deadline

Capture frames, apply a lightweight portrait-matting model, smooth temporal instability with motion-aware state and composite against the selected background. Preserve the original frame until the current result is accepted so inference failure can fall back immediately.

Separate alpha prediction from color-compositing conventions, including premultiplication and the chosen color space. Train with realistic backgrounds, motion blur and illumination; test on real clips rather than only synthetic composites. Bound retained frame state and reset it on camera switches or scene cuts.

3. Calculate the example

For one scalar color channel in a consistent compositing space, alpha = 0.25, foreground = 200 and background = 40 produce 0.25×200 + 0.75×40 = 80. Thresholding alpha to zero produces 40 and loses the partially covered detail. At 30 fps the frame period is about 33.33 ms. If capture/compositing uses 9 ms and inference 20 ms serially, 4.33 ms remains; these assumed timings are not a measured p95 guarantee.

4. Failure cases and trade-offs

Temporal smoothing can trail a fast hand and leak the old background. A binary segmentation metric can look strong while hair edges flicker. Incorrect premultiplied-alpha handling creates halos. Low-light noise may be treated as transparent regions.

Higher-resolution mattes improve edges but cost power and latency. Aggressive smoothing reduces flicker while increasing lag. A coarse fallback should be visibly disclosed or disabled when its artifacts undermine the product.

5. Validate the result

Measure boundary error, temporal flicker, dropped frames, sustained thermal behavior and user-visible artifacts by clip type. Include glasses, hair textures, multiple people and partial bodies. Test scene cuts and camera reconnects for stale state.

6. Interview follow-ups and self-review

How would you handle a transparent object? What if inference misses three frame deadlines?

Reward soft-alpha reasoning, temporal failure analysis, explicit compositing assumptions and sustained-device testing.

Sources and related practice

Technical reference: arxiv.org — MODNet portrait-matting research; pipeline decisions and pixel/budget examples are original.

Exact publication/update date not established in this review. Retrieved September 30, 2026. This reference supports the named technical concept; the proposed workflow and examples are original, not a documented vendor implementation or interview report.

Continue with Gate low-quality uploads before downstream inference; Design a model-serving platform.

Continue your preparation

Choose a connected learning path or browse more ML system design questions. Read our editorial method and attribution policy.