Coding problem
Merge sorted lists from many servers
The task
Each server of a cluster returns its log timestamps in ascending order, and a report needs all of them in one ascending list.
Complete MergeSorted(int[][] arrays). Each inner array is sorted in ascending order, and some may be empty. Return one array that holds every value of every inner array, in ascending order; repeated values stay. The outer array may be empty, and no array is null.
Signature
public static int[] MergeSorted(int[][] arrays)
Examples
[[1, 4], [2, 3]]→[1, 2, 3, 4]. The values of the two arrays interleave.[[-5, 0], [-6, 10], []]→[-6, -5, 0, 10]. The empty array adds nothing.
Limits: Up to 1,000,000 values in up to 100,000 arrays; a value can be any int.
The tests check: no arrays, empty arrays, one array, repeated values, arrays given from largest to smallest, int.MinValue and int.MaxValue, and 1,000 long arrays and 100,000 short arrays in time.
Hints
Your code
Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;
public static class Solution
{
// Merges ascending arrays into one ascending array; repeated values stay.
public static int[] MergeSorted(int[][] arrays)
{
throw new NotImplementedException();
}
}This problem comes with TechInterviewNotes Full Access
Unlock all paid content on TechInterviewNotes.