Align Two Vehicle Trajectories With Banded Dynamic Time Warping

Last updated: November 29, 2026

Quick Overview

Given a recorded ego trajectory and a simulated one as lists of 2D poses sampled at different rates, compute the minimum dynamic time warping cost under a Sakoe-Chiba band of width w and return the alignment path.

Applied Intuition
Coding & Algorithms
Software Engineer
Applied Intuition
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given a recorded ego trajectory and a simulated one as lists of 2D poses sampled at different rates, compute the minimum dynamic time warping cost under a Sakoe-Chiba band of width w and return the alignment path.

Comparing a re-simulated drive against the original log is central to Applied Intuition's log-based testing, and the two rarely have matching sample times. The interviewer checks a 2D DP with a constraint window, reconstruction, and complexity reasoning for long logs.

What the Interviewer Expects
  • Define the DTW recurrence and its base case
  • Restrict cells to a band around the rescaled diagonal
  • Treat cells outside the band as infinite cost
  • Backtrack to recover the alignment path
  • Cut runtime from O(nm) to about O(n w)
Key Topics to Cover
dynamic programming
dynamic time warping
2D DP
trajectory comparison
path reconstruction
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you reduce memory if only the cost is needed?
  • Why can DTW hide a timing regression that matters for safety, and what would you report alongside it?
  • How would you make the metric invariant to a constant spatial offset?
  • How would you choose the band width automatically?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Inputs a (n poses) and b (m poses), each (x, y). Cost of matching two poses is Euclidean distance. Alignment must start at (0,0), end at (n-1,m-1) and be monotone. Band: for row i only colum...

High-Level Design

Classic DTW: D[i][j]=d(ai,bj)+min⁡(D[i−1][j],D[i][j−1],D[i−1][j−1])D[i][j] = d(a_i, b_j) + \min(D[i-1][j], D[i][j-1], D[i-1][j-1]) with D[0][0]=0D[0][0] = 0 and other border cells infinite. Because the rates differ, the band follows the rescaled diagonal rath...


Submit Your Answer
Markdown supported