Skip to the code
cf.
+10 XP

#388 Merge Sorted Activity Feeds

easy

A notifications page merges activity from several services. Each service sends its event timestamps already sorted from oldest to newest.

Write mergeFeeds(feeds) that returns all timestamps from all feeds in one array sorted ascending. Some feeds may be empty, and feeds itself may be empty. Aim for O(N log k) time for N timestamps in k feeds.

Example 1

Input: feeds = [[1,4,9],[2,3,10],[5]]
Output: [1,2,3,4,5,9,10]

Always take the smallest front timestamp among the feeds.

Example 2

Input: feeds = [[],[7],[]]
Output: [7]

Empty feeds add nothing.

Constraints

  • 0 <= k <= 500
  • 0 <= feeds[i].length <= 500
  • Each feed is sorted ascending.
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).