Merge K Sorted Lists Problem
Merge K Sorted Lists Problem — ExecCode Hard DSA Practice
Solve the Merge K Sorted Lists problem on ExecCode. Free online hard DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
You are given an array of k sorted integer lists. Merge all the lists into one sorted list and return it. Each list is already sorted in ascending order (lists are modeled here as plain arrays instead of linked lists).
Examples
Input lists = [[1, 4, 5], [1, 3, 4], [2, 6]]; Output [1, 1, 2, 3, 4, 4, 5, 6]. Input lists = [[1, 2, 3], [4, 5, 6]]; Output [1, 2, 3, 4, 5, 6]. Input lists = [[], []]; Output []
Constraints
k == lists.length 0 ≤ k ≤ 10⁴ 0 ≤ lists[i].length ≤ 500 -10⁴ ≤ lists[i][j] ≤ 10⁴
Practice Merge K Sorted Lists free on ExecCode. Browse DSA problems, topic map, and placement guides.