Merge Multiple Sorted Sensor Streams With Priority Tie-Breaks

Last updated: November 29, 2026

Quick Overview

Given several per-sensor message lists, each sorted by timestamp, produce one globally ordered stream; when timestamps tie, emit sensors in a given priority order, and raise if any input stream is out of order.

Applied Intuition
Coding & Algorithms
Software Engineer
Applied Intuition
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Given several per-sensor message lists, each sorted by timestamp, produce one globally ordered stream; when timestamps tie, emit sensors in a given priority order, and raise if any input stream is out of order.

Applied Intuition's log replay merges IMU, camera, lidar and CAN topics into one playback order, and determinism matters for reproducible simulation. The check is a k-way merge with a heap, a stable tie-break, and a generator so huge logs are not loaded at once.

What the Interviewer Expects
  • Use a min-heap keyed by (timestamp, priority)
  • Keep only one pending message per stream in the heap
  • Make ties deterministic across runs
  • Validate per-stream ordering as you go
  • Expose results lazily with a generator
Key Topics to Cover
heaps
k-way merge
generators
deterministic ordering
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 merge streams read from files that do not fit in memory?
  • How would you handle a sensor whose clock is offset by a known amount?
  • What if one stream stalls in a live system: how long do you wait before emitting?
  • How would you merge already-merged chunks in parallel?
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

streams maps sensor name to a list of (timestamp, payload). priority maps sensor to an int, lower first on ties. Output yields (timestamp, sensor, payload). Payloads may not be comparable, so ...

High-Level Design

Seed a heap with the first message from each non-empty stream. Pop the smallest (ts, priority, sensor, index), emit it, then push that stream's next message. The sensor name and index sit before the...


Submit Your Answer
Markdown supported

Related Questions