Skip to content

Commit 404eec8

Browse files
authored
Create README.md
1 parent 0cc0d23 commit 404eec8

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Given K sorted linked lists of different sizes. The task is to merge them in such a way that after merging they will be a single sorted linked list.
2+
3+
Example 1:
4+
5+
Input:
6+
```
7+
K = 4
8+
value = {{1,2,3},{4 5},{5 6},{7,8}}
9+
Output: 1 2 3 4 5 5 6 7 8
10+
Explanation:
11+
The test case has 4 sorted linked
12+
list of size 3, 2, 2, 2
13+
1st list 1 -> 2-> 3
14+
2nd list 4->5
15+
3rd list 5->6
16+
4th list 7->8
17+
The merged list will be
18+
1->2->3->4->5->5->6->7->8.
19+
Example 2:
20+
21+
Input:
22+
K = 3
23+
value = {{1,3},{4,5,6},{8}}
24+
Output: 1 3 4 5 6 8
25+
Explanation:
26+
The test case has 3 sorted linked
27+
list of size 2, 3, 1.
28+
1st list 1 -> 3
29+
2nd list 4 -> 5 -> 6
30+
3rd list 8
31+
The merged list will be
32+
1->3->4->5->6->8.
33+
```
34+
Your Task:
35+
36+
The task is to complete the function mergeKList() which merges the K given lists into a sorted one. The printing is done automatically by the driver code.
37+
38+
Expected Time Complexity: O(nk Logk)
39+
40+
Expected Auxiliary Space: O(k)
41+
Note: n is the maximum size of all the k link list
42+
43+
44+
Constraints
45+
46+
1 <= K <= 103
47+

0 commit comments

Comments
 (0)