Skip to interview prep
Apexed

36. Merge Two Incident Timelines

EasyEvent streams

Two teams provide timelines of [timestamp, message] pairs, each sorted by timestamp. Merge the timelines into one list ordered by timestamp.

Keep original order within a timeline. At an equal timestamp, take all matching primary entries before matching secondary entries. Keep duplicates and leave the inputs untouched.

Example 1

Input: primary = [[1,"start"],[4,"flag"],[4,"check"]], secondary = [[2,"alert"],[4,"page"],[8,"close"]]
Output: [[1,"start"],[2,"alert"],[4,"flag"],[4,"check"],[4,"page"],[8,"close"]]

Example 2

Input: primary = [[3,"seen"]], secondary = [[3,"seen"]]
Output: [[3,"seen"],[3,"seen"]]

Constraints

  • Each timeline has at most 100,000 entries.
  • Timestamps are integers in [0, 10⁹].

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs in an isolated browser sandbox. Progress and submissions are saved on this device.

Merge Two Incident Timelines — coding interview practice — Apexed