Problem Link: bit.ly/3vjuaGQ Entire LL Sheet: takeuforward.o... Check our A2Z DSA Course: takeuforward.o... Please do give us a like, and subscribe to us if you are new to our channel. Do follow us on our socials: linktr.ee/take...
Thanks for clean code. sudo code have minor issue , please correct it . if ( t1 -> data < t2 -> data ) You missed equal elements . it should be if ( t1 -> data data )
yes. I wondered the same. I came here from leetcode. there some values in the two sorted lists which are same. but what an explanation. I know only basics of linked lists. I was able to undersand well enough
Can't we use dummy node to make it as a copy of the lowest head value of either of the lists (which acts as the head of the new merged list) , and repeat the same process . Will the solution be different ?
I'm confused how the space complexity is O(1)? We are creating a dummy node which extends to hold the nodes of both linked list 1 and linked list 2. Don't the space complexity be O(n1+n2) where n1 are number of nodes in linked list 1 and n2 are number of nodes in linked list 2.
There's a little mistake at the end for handling remaining nodes after either one list has reached null, there should be a another while loop to handle those cases. Also there isn't a java code to the above problem kindly provide one
No,we don't need the while loop here. As we are using the exiting nodes itself,not creating new ones. Suppose n1 is null, so n2 is left. we pointed temp->next as n2. so, from here, link is maintained up to n2 becomes null. Hope you got this.