Merge Two linked lists
Level MEDIUM
Given two linked lists sorted in increasing order. Merge them such a way that the result list is in decreasing order (reverse order).
Try solving without reverse, with O(1) auxiliary space (in-place) and only one traversal of both lists. You just need to return the head of the new linked list, don't print the elements.
Input format :
Output format :
Constraints :
1 <= n, m <= 10^4
Sample Input :
Note: -1 at the end of input is just a terminator representing the end of the linked list. This -1 is not part of the linked list. Size of 1st linked list is 4 and that of 2nd linked list is 3.
Sample Output :
12 9 8 6 5 3 2
Comments
Post a Comment
Please give us your valuable feedback