← Questions

Total covered time per session from overlapping clips

0
NuroCodingLast asked Jul 2025

A coding interview question asked in Nuro's technical phone screen, last asked Jul 2025. It tests intervals, pandas and data manipulation.

A dataset of autonomous-driving clips stores one time interval per row. Clips from the same run can overlap, repeat or leave gaps. For each run, compute the total time covered by its clips, counting overlapping time once. Write it in SQL, then in Python.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • Table clips(set_id INT, run_id VARCHAR, start_time INT, end_time INT, set_number INT); times are offsets in seconds, intervals are half-open [start_time, end_time) with end_time > start_time.
  • SQL: return run_id, cumulative_unique_time.
  • Python: unique_time(rows: list[tuple[str, int, int]]) -> dict[str, int], taking (run_id, start_time, end_time).

Example

run 20250101_122334: [58, 70), [57, 69), [55, 72), [56, 71), [80, 100)
run 20250102_101010: [43, 62)

20250101_122334  ->  37     # [55, 72) is 17, [80, 100) is 20
20250102_101010  ->  19
[0, 10) and [10, 15) in one run  ->  15   # touching intervals don't overlap

Constraints

  • Millions of rows across many runs.

Clarifying questions

  • Are intervals half-open or closed?
  • Group by run, or by set within a run?
  • Can end_time be missing or before start_time?
  • Which SQL dialect (window functions available)?

What a strong answer covers

  • Python: group by run, sort by start, merge while tracking the current end, add up the merged lengths; O(n log n).
  • SQL with "gaps and islands": order by start_time within each run, compute the running maximum of end_time over previous rows, start a new island when start_time is greater than that maximum, then sum MAX(end) - MIN(start) per island.
  • Handling duplicates and fully contained intervals, and touching intervals under half-open semantics.
  • Checking the SQL and Python results against each other on the same data.

Follow-ups

  • Also return, per run, the number of seconds covered by two or more clips.
  • Compute coverage per run per minute bucket.
  • The table is huge and partitioned by date. How does the query scale?

Where it's asked

  • Nuro · Technical phone screen · Last asked Jul 2025

What it tests

intervals · pandas · data manipulation

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding