Merge Sorted Streams

HardData EngineeringArrayBinary SearchMathSorting

Description

Given a list of already-sorted integer arrays, merge them into a single ascending sorted array containing all the elements.

Examples

Input:[[1,4,7],[2,5],[3,6]]
Output:[1,2,3,4,5,6,7]
Explanation:

All the streams are combined and ordered ascending so the merged output is one fully sorted sequence.

Input:[[1,2,3]]
Output:[1,2,3]
Explanation:

All the streams are combined and ordered ascending so the merged output is one fully sorted sequence.

Input:[[5],[1],[3]]
Output:[1,3,5]
Explanation:

All the streams are combined and ordered ascending so the merged output is one fully sorted sequence.

Constraints

  • 1 ≤ number of streams ≤ 10³

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.