Total Online Time From Overlapping Driver App Sessions

Last updated: November 29, 2026

Quick Overview

A driver's app logs online sessions as [start, end) intervals that may overlap because of reconnects on multiple devices; merge them and return the total online seconds along with the merged intervals.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


A driver's app logs online sessions as [start, end) intervals that may overlap because of reconnects on multiple devices; merge them and return the total online seconds along with the merged intervals.

Driver hours feed Uber's earnings guarantees and regulatory reporting, and double-counting overlapping sessions would overpay or misreport. The phone screen interviewer wants sort-then-merge done cleanly, with an explicit rule for touching intervals.

What the Interviewer Expects
  • Sort by start time
  • Merge when the next start is at or before the current end
  • Sum merged lengths rather than raw lengths
  • Decide and state how touching intervals are handled
  • Discuss O(n log n) cost and when input is already sorted
Key Topics to Cover
interval merging
sorting
sweep
half-open intervals
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
  • What if sessions come from a stream in roughly sorted order?
  • How would you compute online time per calendar day when sessions span midnight?
  • What if you need total time with at least two devices online (overlap depth 2)?
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
  • Input: list of [start, end) integer pairs in seconds, with start < end, unsorted, possibly overlapping.
  • Output: (total_seconds, merged_intervals).
  • Half-open intervals mean [0, 10) and `[...
High-Level Design

Sort sessions by start. Walk through them keeping the current merged block [cur_s, cur_e). If the next session starts at or before cur_e, extend cur_e to the max of both ends. Otherwise close th...


Submit Your Answer
Markdown supported