Error
|
|
---|---|
@Ibrahim Nash | 6420 |
@blackshadows | 6376 |
@mb1973 | 5578 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@kirtidee18 | 3673 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3412 |
Complete Leaderboard | |
|
|
@codersgroup18 | 714 |
@Manikanta punnam | 579 |
@sriramgoparaju99 | 532 |
@yashkaril4 | 517 |
@praveenbgp6 | 517 |
@prankursharma31 | 489 |
@rdakka | 465 |
@sonamnigam1999 | 441 |
@purohitmn02 | 427 |
@sonamkumari63928 | 426 |
@ShubhankarPandey | 419 |
Complete Leaderboard |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have merged list as 2, 3, 5,
10, 15, 20, 40.
Example 2:
Input:
N = 2, M = 2
valueN[] = {1,1}
valueM[] = {2,4}
Output:1 1 2 4
Explanation: After merging the given two
linked list , we have 1, 1, 2, 4 as
output.
Your Task:
The task is to complete the function sortedMerge() which takes references to the heads of two linked lists as the arguments and returns the head of merged linked list.
Expected Time Complexity : O(n+m)
Expected Auxilliary Space : O(1)
Constraints:
1 <= N, M <= 104
1 <= Node's data <= 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes