Match Camera Frames to Nearest Lidar Sweep Within Tolerance
Last updated: November 29, 2026
Quick Overview
Given sorted camera frame timestamps and sorted lidar sweep timestamps (milliseconds), return for each camera frame the index of the closest lidar sweep if it lies within a tolerance, otherwise -1. Aim for linear time.
Nuro
November 29, 20260
0
0 solved
Given sorted camera frame timestamps and sorted lidar sweep timestamps (milliseconds), return for each camera frame the index of the closest lidar sweep if it lies within a tolerance, otherwise -1. Aim for linear time.
Sensor fusion on an autonomous vehicle only works if each camera image is paired with the lidar sweep captured closest in time, so time alignment is a natural warm-up for Nuro's autonomy software screens. The interviewer checks whether you use the sorted order with two pointers instead of a nested scan, and how carefully you define ties and the tolerance boundary.
What the Interviewer Expects
- Clarify tie-breaking and whether the tolerance is inclusive
- Use a monotonic two-pointer sweep rather than an O(n*m) scan
- Handle an empty lidar list and frames before the first or after the last sweep
- State O(n + m) time and O(1) extra space beyond the output
- Mention why binary search per frame is an acceptable alternative at O(n log m)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you adapt this if lidar messages arrive out of order by a few milliseconds?
- What changes if each sweep can be used by at most one camera frame?
- How would you match three sensor streams at once?
- How do clock offsets between sensors affect this and how would you correct them?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: camera_ts and lidar_ts, both sorted ascending, and tol. Output: a list the same length as camera_ts, holding the index of the nearest sweep or -1 if the nearest one is farther than `to...
High-Level Design
Because both streams are sorted, the nearest sweep for successive camera frames never moves backward. Keep a pointer j into the lidar list. For each frame, advance j while the next sweep is strict...