intuation behind the optimal approach🔥🔥, legend ....
@amanshrivastav04056 ай бұрын
You need to be a superhuman to discover the third approach on your own! Thankssssss alloooooottt striver 😇
@BholaSingh-m8z4 ай бұрын
Sir you, covers brute-force, optimized approaches, and even a killer third option! Well done, keep up the good work!
@vibhavsharma27244 ай бұрын
A big salute to striver and his third approach 🫡
@codingsoham7 ай бұрын
The last algorithm man. After learning about it, it feels like why I didn't I think about that possibility. Thank you Striver for such a great explanation.👌👌
@tanish_gupta11 ай бұрын
Best video for this problem on youtube till date. Covered everything from brute-force to the best-optimised way to solve this problem. Kudos Striver!! Enjoying this path and the playlist.
@technosujeet9 ай бұрын
third approach literally blown my mind
@bruvhellnah5 ай бұрын
"literally"
@shaikhsoheel867311 ай бұрын
Quality content brother I was waiting for Linkedlist God bless you brother
@RajeevCanDev11 ай бұрын
teachers like him comes in a decade or more, bhaiya please try to upload stacks and queues and strings as well
@preethilatadanguria69466 ай бұрын
saw many videos to understand the 3rd approach but then landed on this video which has ended by search.thank u stiver for brilliant explanation.
@blurbmusic15072 ай бұрын
optimal approach just GENIUS!! hats off captain!!
@pratyushbhatt171217 күн бұрын
Beautiful Optimal approach. Thanks Striver!
@shashankyadav89773 ай бұрын
The hashing one can be done in one iteration as well. We can insert in map acc to both LL at once. And check at that moment only if the freq is >1. Code - C++ int intersectPoint(Node* head1, Node* head2) { Node*p1=head1; Node*p2=head2; unordered_map hashmap; while(p1||p2) { if(p1) hashmap[p1]++; if(p2) hashmap[p2]++; if(hashmap[p1]>1) return p1->data; if(hashmap[p2]>1) return p2->data; p2=p2->next; p1=p1->next; } return -1; }
@LinhHoang-ml1qoАй бұрын
but it takes more space complexity while the last solution of Striver only takes O(1)
@ujjawalchourasiya39888 ай бұрын
Aayla Jaado in 3rd approach Maja arha hai ab problems krne m . Thanks striver bhaiya for delivering such approaches things gets better and understandable ❤
thanks bhaiya for providing such an amazing content
@ritikshandilya70756 ай бұрын
Thankyou so much for great explanation @Striver
@knowthrvdo8 ай бұрын
NICE LECTURE AND PLZ UPLOAD REMAINING LECTURES OF A TO Z SDA SHEET PLZ THEY ARE VERY HELPFULL FOR US
@kushalswarup26625 ай бұрын
mind blowing method. cant believe woahh
@kushalkollu86285 ай бұрын
damn man! what an idea for the optimal approach
@anastasiiamaslova422011 ай бұрын
great explanation!
@tejaspatel69652 ай бұрын
damn the third approach is beautiful
@prajapati-suraj2 ай бұрын
if anyone does figure out the third approach on his own, he is a genius.........
@MohammadEhshan-ve6uz2 ай бұрын
me
@piyushrawat46682 күн бұрын
damnn🔥🔥the third approach!!!
@utkarshpundeer073 ай бұрын
3rd approach was a 🤯🤯
@vaibhavbhatt73411 ай бұрын
i have taken a course of dsa and in that course one teacher tell the 2 approach till this date I think this approach is optimized but today (wake up to reality ho gaya)
@ranjeetkumaryadav18373 ай бұрын
Thanks sir Last one is 🔥🔥
@SHIVAMSINGHPARIHAR-w1i2 ай бұрын
Was asked to me in Oracle Intern Technical Round 1 Interview
@prathameshjadhav294211 ай бұрын
So help full video
@hashtagcc7 ай бұрын
The first time who have invented this algo must be from another dimension😙
@prathameshjadhav294211 ай бұрын
Nice teaching
@rohandas62984 ай бұрын
Why the time complexity of the last approach is not O(2 * (n1 + n2)) ??
@BhavanaReddy154 ай бұрын
Same doubt
@Fe-ironman4 ай бұрын
@@BhavanaReddy15 because you're traversing both linked list simultaneously not separately. for example while traversing first linked list you traverse m step and reach null then traverse at maximum n step at worst case when there's no match and simultaneously you're traversing through the other linked list first n step and then m step at worst case when no match so the complexity is O(m+n)
@NazeerBashaShaik6 ай бұрын
Understood, thank you.
@selene87214 ай бұрын
Thank you so much!!
@pratyushtripathi172810 ай бұрын
Understood 😊
@kale-lb5pr9 ай бұрын
node* intersectionY(node* head1, node* head2) { if (head1 == NULL || head2 == NULL) return NULL; node* temp = head1; map mpp; // Insert nodes of the first linked list into the map while (temp != NULL) { mpp[temp] = 1; temp = temp->next; } // Traverse the second linked list and check for intersection temp = head2; while (temp != NULL) { if (mpp.find(temp) != mpp.end()) { return temp; } temp = temp->next; } return NULL; } int main() { vector arr={3,1,4,6,2}; vector b={1,2,4,5,4,6,2}; node *head1=convertarrtoLL(arr); node* head2=convertarrtoLL(b); node* head=intersectionY(head1,head2); cout
@manga_mania.11 ай бұрын
thank you striver
@AlaskaAlaska-xq4gk4 ай бұрын
zeherrrrrrr teaching
@saswatrath46467 ай бұрын
3rd approach was awesome haha
@DeepakPatel-d5v7 ай бұрын
Thanks a lot bhaiya
@harigs722 ай бұрын
Understood.🎉❤
@YourCodeVerse9 ай бұрын
Understood✅🔥🔥
@DeadPoolx17122 ай бұрын
UNDERSTOOD;
@ManishLakkavatri11 ай бұрын
Understood!
@Learnprogramming-q7f8 ай бұрын
Thank you Bhaiya
@SiddhesDas24 күн бұрын
small correction if (n1 < n2) { return collisionPoint(headB, headA, n2 - n1); } else { return collisionPoint(headA, headB, n1 - n2); } baaki first class
@ramkrishnapatil2105Ай бұрын
dimag hil gya bhai 🤐🤐
@khalasianiket8164 ай бұрын
understood ❤
@shelkeonkaАй бұрын
In 2nd approch when N1 > N2 then in collision funtion we have to bring the t1 at alin postion which matches the t2 but the code is just work for when N1 < N2 ??
@HeetMungra-g9l12 күн бұрын
hey!! what if we start traversing from end of the both list and return the last node where they are equal??
@hajeeramohamad7641Ай бұрын
in the second approach - what if the length of both the linked lists is same? how will the collision function work then?
My simple java code public class Solution { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { ListNode temp1=headA; ListNode temp2=headB; while(temp1!=temp2){ if(temp1==null){ temp1=headB; temp2=temp2.next; } else if(temp2==null){ temp2=headA; temp1=temp1.next; } else{ temp1=temp1.next; temp2=temp2.next; } } return temp1; } }
@rishipatwa68232 ай бұрын
can we do like reverse both ll and then check them until they are equal ..once unequal return the prev node
@kale-lb5pr9 ай бұрын
how does storing nodes directly make difference if we encounter same node value form second linked list why hashmap was showing no???/
@factswithjenny99 ай бұрын
thanks
@chiragbansod82527 ай бұрын
understood
@ArpanChakraborty-do6yz8 ай бұрын
Understand 31:53
@harshitjaiswal94399 ай бұрын
understood.
@akashumre2211 ай бұрын
Bro thanks
@nehapimpalkar39610 ай бұрын
understood!
@harshuke583111 ай бұрын
Understood
@SurajSharma-z9p9 ай бұрын
Please correct me if I'm wrong. If the two linked lists are never intersecting and are of different lengths, this will be a infinite loop because t1 will never be equal to t2 and we'll keep on interchanging them with heads in case of null
@shivangairan69049 ай бұрын
Bro even if they are non-touching, after the first exchange for both they will come in parallel so the loop will terminate when they reach null together
@SurajSharma-z9p9 ай бұрын
@@shivangairan6904 Understood. Thanks
@harshuke583111 ай бұрын
Understood 30lakh
@fsyk13065 ай бұрын
Hey Striver, for the last algorithm, wouldn't it work too if when T1 or T2 reach NULL , they can be put back to Head1 or Head2 respectively? T1 goes back to Head1 and T2 goes back to Head2, it's working the same.
@aryasharma692 ай бұрын
Try with different example like N1=5 & N2= 7, then you will get to know why it fails
@RAHULSHARMA-on6tm5 ай бұрын
in this code if you remove the if t1==t2 return t1, it should work fine right? Because the while loop will break in case both of them become equal, but the problem is, removing this condition will cause an error to appear. Can someone please answer this issue. Thanks
@rahulnegi40272 ай бұрын
i would be simpler if these were circular h1->tail = h2 & h2->tail = h1;
@Chlo_Chle_Hum3 ай бұрын
is circular linked list important?...if yes,from where to do..someone pls suggest
@LukmaansStack8 ай бұрын
striver bhai we need string please
@NonameNoname-f2t8 ай бұрын
SUUUUUUUUPERRRRRRRRRBBBBBBBBBBB
@VineetChelani130411 ай бұрын
can we even compare each node of one LL to Other LL and get the first intersection ??
@dhrumilparmar150511 ай бұрын
that's brute force approch..still works but time complexicity will be of O(n^2).here we will get in O(max(len(t1),len(t2)) + distance of intersection from smallest LL)....somewhat linear complexity
@SuvamoySamanta-n2xАй бұрын
why use this line mpp.find( temp) != mpp.end(); please explain this line
@SuvamoySamanta-n2xАй бұрын
!= use why
@roshnisingh73649 ай бұрын
please share the code for last approach
@ekjotsingh96097 ай бұрын
Why wasn't a set used in the hashing approach? Wouldn't that be better?
@aryasharma692 ай бұрын
That will still take O(n) space
@kale-lb5pr9 ай бұрын
pls can anyone explain me what is the difference in storing a node in hashmap and a value ? if the same value is present in second LL also why doesnot it indicate yes? pls give me hintts...
@lot2say5909 ай бұрын
Because Node is a class which consists of the address of the data too. Hence while comparing the same value, we are not checking if it's in the same address, so we can't conclude on that. So to check if it's in the same address, we compare the whole Node and not just the value.
@djpro64139 ай бұрын
@@lot2say590 Thanks bro same question arise to me
@stellar34964 ай бұрын
waatha idhan da coding 🤯🤯
@naturesrevolution5 ай бұрын
anyone pls answer in second approach what happens if t1 and t2 contains same element before linking?
@qwerty209175 ай бұрын
No problem in that case too bro.. cause we are comparing the pointers themselves (whether they point at same position/node or not),not their values.. Hope this helps..
@naturesrevolution5 ай бұрын
@@qwerty20917 thank you bro
@utkarshsingh331911 ай бұрын
❤❤
@jagadeeshp116310 ай бұрын
what if we take 3->1 and 1-> it fails ??
@Shivi325905 ай бұрын
thank you!
@dhakerk09410 ай бұрын
agar dono linked list me koi intesection point nhi hai to
@swapnil714224 күн бұрын
third option ke liye thought process rahega, ye dimag me kaise aayega
@kale-lb5pr9 ай бұрын
pls explain my concern im just a beginner dont break my spirit like that!!!!!!!!!!!
@moksh45510 ай бұрын
hey striver it's showing an error if i submit the exact code on leetcode on the test case [ 1, 2 ] and [ 2 ] , could you explain why
@moksh45510 ай бұрын
ahh got it we need to add a check after we interchange temps with heads as well
@yourhonestbro2175 ай бұрын
This question was not that difficult, my first approach was the optimal one