Even if there are oceans of content available online on a same topic, mycodeschool always stands out of them. It's kinda sad why you guys stopped making more videos.
@pulkitsharma71054 жыл бұрын
The founder of mycodeschool died in an accident 5 years ago
@sheruloves91904 жыл бұрын
@@pulkitsharma7105 Fuck.. was that the one delivering dsa topics?
@PrathamGupta24084 жыл бұрын
RIP
@merohan6194 жыл бұрын
@@sheruloves9190 yes, he was a national level coder.
@saketkumar58843 жыл бұрын
@@sheruloves9190 No
@lukestumpf15245 жыл бұрын
Make sure to set d = -d in the swap section of code so if you need to swap you actually go through all of the values you need. Great video!
@swami26723 жыл бұрын
Thanks for the video. Instead of swapping, just traverse the larger linked list in advance. CODE: /** Definition for singly-linked list. class ListNode { public int val; Public ListNode next; ListNode(int x){ val = x; next = null; } } */ public class MergePoint { public int getLength(ListNode a) { int count = 0; ListNode temp = a; while (temp != null) { count++; temp = temp.next; } return count; } //Traverse the larger list by d times //So both the starting points of the list will come on the same track //Starting point of b will be now 40 and not 200 public ListNode traverseD(ListNode a, int d) { for (int i = 0; i < d; i++) a = a.next; return a; } public ListNode getIntersectionNode(ListNode a, ListNode b) { int a_length = getLength(a); int b_length = getLength(b); int d; //Whoever is larger will traverse in extra if (a_length > b_length) { d = a_length - b_length; a = traverseD(a, d); } else { d = b_length - a_length; b = traverseD(b, d); } //Now a and b are on the same track //100 on A and 40 on B while (a != null && b != null) { if (a == b) return a; a = a.next; b = b.next; } //If there are no merging points return null; } }
@arjitaagrawal2703 жыл бұрын
Great explanation..the practical example made it even more interesting and easy to understand. Such examples are appreciated
@subham-raj5 жыл бұрын
*If you use HashSet then time-complexity would be O(m + n) and Space-complexity would be either O(n) or O(m) depends on which linked list data you would like to store in the HashSet.*
@subham-raj5 жыл бұрын
FOUND ONE MORE COOL SOLUTION: int FindMergeNode(Node headA, Node headB) { Node currentA = headA; Node currentB = headB; //Do till the two nodes are the same while(currentA != currentB){ //If you reached the end of one list start at the beginning of the other one //currentA if(currentA.next == null){ currentA = headB; }else{ currentA = currentA.next; } //currentB if(currentB.next == null){ currentB = headA; }else{ currentB = currentB.next; } } return currentB.data; }
@nikhilnikhil35173 жыл бұрын
@@subham-raj how do you ensure that this code runs for the linked lists having no intersection
@harikishanpuvvala59737 жыл бұрын
This video is good. With an exception that it is mistyped as 80 instead of 30 in the list A for the node 140.
@TheKundan1110 жыл бұрын
Nice explanation !!!! And good approach of solving a problem first in brute force and then going on optimizing it .
@flockerlocker10 жыл бұрын
To decide the longer list you are performing a swap , but you can also do without swap using lengths of both lists if (lengthOfB > lengthOfA) //Move B till lengthOfB - lengthOfA; else if (lengthOfB < lengthOfA) //Move A till lengthOfA - lengthOfB;
@subham-raj5 жыл бұрын
Bro you have to swap the head pointers as you might traverse the wrong list. Think about it.
@krsingh.shubham4 жыл бұрын
mah-god, after moving through so many tutorials for this problem, none explained me with this much clarity.
@ytg66633 жыл бұрын
Ok. Thank me later
@rajasekharkalakangeri17086 жыл бұрын
finding length ofeach linked list also takes some time here. Here is my approach 1. Insert all the nodes of linked list A to a simple array (X) 2. Insert all the nodes of linked list B to a simple array (Y) 3. Start a loop to fetch from both the arrays starting from the last element, every time nodes from both arrays will be equal. At an instance nodes from arrays go unmatch, break the loop and return the previous instance as the output.
@rajasekharkalakangeri17086 жыл бұрын
if it is a double linked list, we don't require any arrays
@ritikashishodia38293 жыл бұрын
great explanation i am solved this problem at hacker rank I do not understand what is actually merge point ....hacker rank give mycodeschool channel link ..then finally i understand what is merge point.
@yasser_hussain6 жыл бұрын
A set implemented as hash has O(1) insert, delete, find time complexity. So even for Hashset solution we will get O(m+n) time albeit space complexity will be O(n).
@codingcart4 жыл бұрын
kzbin.info/www/bejne/jZSylZaLfbR0Z68
@prabhu22636 жыл бұрын
What happens in the following cases:- 1. If the common nodes are in the starting of both linked lists? like L1 - 1,2,3,4,5,6,7,8. L2 - 1,2,3,9,10,11,12. 2. If both the lists has same length?. Then we end up again in the equivalent method of brute force.
@pymondo11476 жыл бұрын
1. It seems in singy linked list we can never have node pointing two address . So this is invalid. It will be unique memory for both the lists.
@divyamsh21155 жыл бұрын
if the first node itself is matching then return the first node,else follow this approach!
@Shree__984 жыл бұрын
Sooo well explained..🎉 You deserve appreciation 👏
@CSshreyas8 жыл бұрын
what if the liked lists are modified in way that they have some diverging point after they merge? and the lists are of different length? something like two trains have just few common stations Train 1 stops at station A -> B -> C -> D -> E -> F. Train 2 stops at station H -> I -> C -> D -> J -> K -> L -> M
@zoltanie7 жыл бұрын
then it's not a linked list!
@ChandraShekhar-by3cd4 жыл бұрын
Your explanation was Perfect!..Please upload more videos
@codingcart4 жыл бұрын
kzbin.info/www/bejne/jZSylZaLfbR0Z68
@rishabsharma53074 жыл бұрын
he died
@jaysahu3576 жыл бұрын
very very nice you teach me many thing in one video about how to optimize the code,thank a lot
@sidddcloud5 жыл бұрын
Also you can join the tail of both list. Then find the starting point of loop
@prateektewary75263 жыл бұрын
For that you will require a doubly linked list to traverse back from tail.
@FitnessChaos3 жыл бұрын
Good explanation but the optimal solution is not dynamic. You actually don’t know which of the A or B nodes is bigger so you have to check and iterate for that too
@avnishgupta87319 жыл бұрын
sir in this there is error at 4:40 in the link list A the 2 nd node which has data value 6 has the value in the next pointer 30 and not 80. plz correct it
@jamesward29466 жыл бұрын
This is a great tutorial. Thanks for the corner cases explanation at the end :).
@codingcart4 жыл бұрын
kzbin.info/www/bejne/jZSylZaLfbR0Z68
@thinhnguyenvan70033 жыл бұрын
I think in method 2, we use dictionary will give you linear time complex
@chitrasomasingh538810 жыл бұрын
i didnt understand the condition: if(addresses.find(A)!=addresses.end()) what is the use of addresses.end overhere ??
@mycodeschool10 жыл бұрын
Chitrasoma Singh There is this concept of iterators in standard template library of C++.. Go through this - community.topcoder.com/tc?module=Static&d1=tutorials&d2=standardTemplateLibrary
@s20_d8410 жыл бұрын
Nice explanation with real tym example .. I liked this tutorial ... keep it up :)
@sriramiyer98404 жыл бұрын
in the last approach, d should be set equal to abs(n-m), i.e., d = abs(n-m); as the value of n-m can be negative too
@naveendara86464 жыл бұрын
Check the if statements It has a d=m-n statement
@kaustavbora20244 жыл бұрын
Swap function is wrong Please update it Right One:- if(m > n) { SinglyLinkedListNode* temp; temp=head1; head1=head2; head2=temp; d=m-n; }
@suguruchhaya31943 жыл бұрын
Your video was so damn easy to understand. RIP and thank you.
@blasttrash6 жыл бұрын
Is this Harsha? May his soul rest in peace. :'(
@subham-raj5 жыл бұрын
What happened to him?
@yashpreetbathla46535 жыл бұрын
@@subham-raj He passed away in accident :"(
@vikranttyagiRN4 жыл бұрын
RIP
@anolhshete8 жыл бұрын
In the last solution the time complexity will be O(max(m,n)) ? Is it correct or O(m+n) is correct , I know we can remove the constant factor but which is logically correct.
@sidddcloud5 жыл бұрын
I think o(m+n) means whichever is greater. So they are basically same.
@ravindercool0059 жыл бұрын
Very nice explanation ..Thnks alot sir .
@magicsmoke09 жыл бұрын
How would you do the Set approach in C# where references to managed objects don't have addresses (you would have to do some trickery with the GCHandle to get it)?
@jsrgbh08 жыл бұрын
Have seen few of your videos and liked them all. Most of your solutions are focused on C and C++, Possible for you to provide the Java code snippet as well?
@ShekharKumar803410 жыл бұрын
Nice and simple explanation sir.. Thanks :)
@zy55229 ай бұрын
Thanks😊
@vijayendrasdm10 жыл бұрын
For the approach 2, why did not you use unordered_map ? unordered_map has insertion/retrieve complexity of O(1). By using this we could have reduced TC to O(n) . Correct me if I am wrong
@lorenzocastillo685010 жыл бұрын
O(M+N) time, but obv you need space for the hash table.
@udaykiran-yi2dv8 жыл бұрын
excellent Explanation
@liwaiyip17694 жыл бұрын
Amazing job! Thank you very much.
@TheAbhijeetidiot10 жыл бұрын
please upload some lectures on conditional statements and loops, arrays, functions and storage classes.
@seemcat5 жыл бұрын
Great explanation. Thanks!
@AddieInGermany7 жыл бұрын
Nicely explained. Thanks
@suguruchhaya31943 жыл бұрын
Who else is comming from the HackerRank question? Just want to let you know that you have to return the '.data' of the node instead of the node itself in the question.
@nikhilnikhil35173 жыл бұрын
Shouldn't the time complexity be O(max(m,n)) as we are basically traversing the longer list fully in worst case i.e. when no merge point is found.
@abhishekkaukuntla67628 жыл бұрын
What if the first node itself is the merge point? What's the rule to evaluate d then, considering length(A) < length(B)? If we skip d places, we would miss the merge point.
@Gre058 жыл бұрын
+Nikolay Jivkov I didn't understand it, because if the first node is merge with first node of B, we can skip it.
@mithessen8 жыл бұрын
It seems that there is an implicit assumption that after the merge point the lists remain same throughout. If there were multiple merge points to be considered such as in lists which converged, diverged and then re-converged, then it would need additional checks and balances.
@preetsinghkhalsa12046 жыл бұрын
A list cannot diverge since there's only one parameter for next node in the structure.
@yasser_hussain6 жыл бұрын
That can only happen if both lists are identical. Remember linked lists can't diverge.
@NiranjhanaNarayanan8 жыл бұрын
Hey when we are passing the head node pointer (for the length function), isn't that by reference? So when we traverse it, doesn't the value get modified and the value of the start of the linked list get lost?
@NiranjhanaNarayanan7 жыл бұрын
Yeah, got that, thanks!
@aayush54745 жыл бұрын
waht will main look like?
@Niteshkumar-zd3kr5 жыл бұрын
Are you comparing addresses or the values?
@subham-raj5 жыл бұрын
The node as a whole.
@codingcart4 жыл бұрын
kzbin.info/www/bejne/jZSylZaLfbR0Z68
@anupamshankardey87377 жыл бұрын
which IDE have you used during this lesson?
@chiranjeevthomas47966 жыл бұрын
it's codeblocks
@bantykumar57346 жыл бұрын
Notepad++
@KhaledChikhComptable10 жыл бұрын
Good tutorial
@siddharth__pandey6 жыл бұрын
your website is showing a bad gateway error.. please fix
@mayanksrivastava44527 жыл бұрын
amazing video
@AbhayKumar-uw8or4 жыл бұрын
i think its wrong as what if the d more nodes itself contain the merge point that you have just skipped to make the length same
@redraushan4 жыл бұрын
I was banging my forehead for hours thinking how could two separate linked list can have a merge point, thank god I finally am here.
@sureshdharavath119110 жыл бұрын
In brute force without finding the length lists can't it possible ? I guess by creating two temporary nodes which points to the head of the given nodes.
@mycodeschool10 жыл бұрын
Suresh D.Naik Can you detail your approach?
@saurabhchauhan15678 жыл бұрын
+Suresh Dharavath it is possible but i will not change the complexity of the solution
@sartmeh18 жыл бұрын
He means by using two while loops with each while loop designated with either list to check for NULL in link lists.This can save up a little bit of memory but still the complexity shall remain same i.e. O(mn).
@CSshreyas8 жыл бұрын
what about going to the end of the list and traverse back until there the nodes have same value?
@codingcart4 жыл бұрын
kzbin.info/www/bejne/jZSylZaLfbR0Z68
@curiosity98614 жыл бұрын
At 1:29 we have different addresses of value 7 in linked list 1 and linked list 2 so how we can check for the equality of it?
@prateektewary75263 жыл бұрын
Here we are not searching for similar values of nodes rather a "merge point". The two linked list at 1:29 have same values of two nodes but no merge point.
@hassnainali68725 жыл бұрын
Can't we recursively go to the end of each list, and on each return, compare the pointers with each other up till the last point where they are similar ?
@redraushan4 жыл бұрын
That would still be brute-force way way of doing it, basically you are asking why to do merge sort if be can do bubble sort, I think that's the difference.
@parmeetsingh74106 жыл бұрын
can we compare node's data instead of node's address???
@utsavdahiya37296 жыл бұрын
No, data values are not unique to each node
@parmeetsingh74106 жыл бұрын
utsav dahiya can you please explain through an example,I am still confused?
@mavrck1596 жыл бұрын
SnackDown is here! Only one global champion will take the title home. Let the Code War begin! Registrations are now OPEN for SnackDown 2019! www.codechef.com/snackdown?ref=sssshhhh
@shruthib66356 жыл бұрын
what if 2 lists diverge after some point.... How are we handling this case
@shankarn40216 жыл бұрын
The linked list(mentioned in the video) has only one next* pointer, so it's impossible to have the list point to 2 different nodes.
@RajbirYadav9 жыл бұрын
awesome!
@FrozenByTheSun6 жыл бұрын
Is this Harsha?
@blasttrash6 жыл бұрын
I had the same question. If it was, I just feel so sad. May his soul rest in peace.
@urcristiano778826 жыл бұрын
who is harsha ?
@blasttrash6 жыл бұрын
Harsha is one of the two guys who started this channel. Apparently Harsha met with accident or something.
@urcristiano778826 жыл бұрын
okayy thanks
@mybozlo9 жыл бұрын
In #3 case, what if the merge point in d area ?
@SourabhVartak19859 жыл бұрын
+IL JUN LEE The d area is where one linked list has more elements than the other linked list. So, the merge point can not occur in the d area because only one list is active there.
@arpitsatnalika4 жыл бұрын
This code will fail for linked list like this [4,1,8,4,5] and [5,6,1,8,4,5]
@kunalsoni76814 жыл бұрын
😍😍😍😊😊😊😊
@lyfokzz38484 жыл бұрын
unfortunatly he passed away bro...
@kunalsoni76814 жыл бұрын
@@lyfokzz3848 what it mean bro
@lyfokzz38484 жыл бұрын
The instructors name was Late Harsha suryanarayan. He was the best coder of all time.You can google it for more information.