Merge Sorted Sensor Streams From Multiple Apple Watch Sensors
Last updated: November 29, 2026
Quick Overview
An Apple Watch produces k streams of (timestamp, sensor, value) readings, each already sorted by timestamp. Merge them into one stream sorted by timestamp, breaking ties by stream index, using memory proportional to k rather than total readings.
Apple
November 29, 20260
0
0 solved
An Apple Watch produces k streams of (timestamp, sensor, value) readings, each already sorted by timestamp. Merge them into one stream sorted by timestamp, breaking ties by stream index, using memory proportional to k rather than total readings.
Sensor fusion pipelines on watchOS combine accelerometer, gyroscope and heart rate data into one timeline. The interviewer is checking the k-way merge with a heap and whether you can make it lazy so it works on iterators, not just lists.
What the Interviewer Expects
- Use a min-heap keyed by (timestamp, stream index)
- Seed the heap with the head of every non-empty stream
- Pop, emit, then push that stream's next reading
- Write it as a generator that consumes iterators lazily
- State O(N log k) time and O(k) space
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
- Streams can deliver slightly out-of-order readings within a 50 ms tolerance; how do you reorder?
- One sensor stalls; how do you avoid blocking the merged output forever?
- Merge on-device with tight memory, then upload in batches.
- Deduplicate identical readings that arrive on two streams.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a list of k iterables, each yielding (ts, sensor, value) tuples in nondecreasing ts. Output: a generator yielding all readings in nondecreasing ts, ties ordered by stream index then by or...
High-Level Design
Turn each input into an iterator. Push the first reading of every stream into a heap as (ts, stream_idx, reading). Including the stream index makes ties deterministic and also prevents Python from c...