Z26
Merge K Sorted Lists
Problem Statement & Objective
You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it.
Function Signature (Python)
merge_k_sorted_lists(lists: list[list[int]]) -> list[list[int]]Input & Output Contract
Output Rule:[[değer, liste_indeksi], ...] artan değerde; eşitlikte küçük liste indeksi önde. Boş girdi [].
System Constraints
k == listeler.length
0 <= k <= 10^4
0 <= listeler[i].length <= 500
-10^4 <= elemanlar <= 10^4
Her liste artan sıradadırExample Execution Walkthrough
listeler = [[1, 4, 5], [1, 3, 4], [2, 6]]
[[1,0],[1,1],[2,2],[3,1],[4,0],[4,1],[5,0],[6,2]]
İki tane 1 vardır: liste 0, liste 1'den önce gelir.
listeler = [[1, 3], [1, 2]]
[[1,0],[1,1],[2,1],[3,0]]
Düz sorted([1,3,1,2]) = [1,1,2,3] kaynak listeyi taşımaz.Example Test Scenarios (3)
Example 1
Input:
[[[[1,4,5],[1,3,4],[2,6]]]]Expected Output:
[[[1,4,5],0],[[1,3,4],0],[[2,6],0]]Example 2: Boş Girdi
Input:
[[[]]]Expected Output:
[]Example 3: Tek Empty List
Input:
[[[[]]]]Expected Output:
[[[],0]]