The interview problem

Practice prompt

Compare two sequences that express similar shapes at different speeds.

Original practice, not a reported company interview. Scenarios and numbers are illustrative. Interview date: not applicable. Sources retrieved October 1, 2026.

1. Scope and worked approach

Build local costs and dynamic programming D(i,j)=cost(i,j)+min(D(i−1,j),D(i,j−1),D(i−1,j−1)). Define endpoint conditions and allowed warping. A window can constrain implausible alignments and reduce computation.

2. Trace the design or derivation

Local cost matrix
  → constrained recurrence
  → backtracked path
  → interpretation

For long recordings, choose constraints from plausible timing variation rather than optimizing test accuracy. Report runtime and the fraction of alignments hitting the window boundary; that can reveal when the permitted timing model is too restrictive.

3. Calculate the example

Sequences [1,2,3] and [1,1,2,3] have zero total absolute-difference cost along a path that matches the first 1 twice. Euclidean elementwise comparison cannot directly express that alignment.

4. Failure cases and trade-offs

Unrestricted warping can make different events look similar. A low cost is not proof that two sequences share a cause. Normalize path length only under a clearly stated metric.

5. Validation, follow-ups and self-review

Inspect alignment paths, not just scores. Follow-up: how would online alignment differ? Self-review: show recurrence, boundary conditions and warp limits.

Sources and related practice

Technical reference: tslearn.readthedocs.io — Dynamic time warping and constraints; guide explicitly uses absolute local costs.

Source publication/update: Not established. Retrieved October 1, 2026. The workflow, calculations and review exercises are original; this reference is not evidence that a company asked this question.

Continue with Align supplied subtitles to speech; Find action intervals inside long videos.

Continue your preparation

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