Skip to the code
cf.
+10 XP

#111 Merge Two Activity Feeds

easy

A project dashboard shows one activity feed built from two sources: comments and commits. Each source is an array of timestamps (in seconds), already sorted from oldest to newest.

Write mergeFeeds(comments, commits) that returns a single array with every timestamp from both sources, sorted from oldest to newest. Keep repeated timestamps. Don't call sort: use the order you already have.

Example 1

Input: comments = [100,400,900], commits = [200,300,1000,1200]
Output: [100,200,300,400,900,1000,1200]

The feeds interleave by time.

Example 2

Input: comments = [50,60], commits = []
Output: [50,60]

With no commits, the feed is just the comments.

Constraints

  • 0 <= comments.length, commits.length <= 100000
  • Both arrays are sorted ascending.
  • 0 <= timestamps <= 10^9
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).