L12. Find the intersection point of Y LinkedList

  Рет қаралды 80,014

take U forward

take U forward

Күн бұрын

Пікірлер: 151
@hardikpatel352
@hardikpatel352 6 ай бұрын
intuation behind the optimal approach🔥🔥, legend ....
@amanshrivastav0405
@amanshrivastav0405 6 ай бұрын
You need to be a superhuman to discover the third approach on your own! Thankssssss alloooooottt striver 😇
@BholaSingh-m8z
@BholaSingh-m8z 4 ай бұрын
Sir you, covers brute-force, optimized approaches, and even a killer third option! Well done, keep up the good work!
@vibhavsharma2724
@vibhavsharma2724 4 ай бұрын
A big salute to striver and his third approach 🫡
@codingsoham
@codingsoham 7 ай бұрын
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_gupta
@tanish_gupta 11 ай бұрын
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.
@technosujeet
@technosujeet 9 ай бұрын
third approach literally blown my mind
@bruvhellnah
@bruvhellnah 5 ай бұрын
"literally"
@shaikhsoheel8673
@shaikhsoheel8673 11 ай бұрын
Quality content brother I was waiting for Linkedlist God bless you brother
@RajeevCanDev
@RajeevCanDev 11 ай бұрын
teachers like him comes in a decade or more, bhaiya please try to upload stacks and queues and strings as well
@preethilatadanguria6946
@preethilatadanguria6946 6 ай бұрын
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.
@blurbmusic1507
@blurbmusic1507 2 ай бұрын
optimal approach just GENIUS!! hats off captain!!
@pratyushbhatt1712
@pratyushbhatt1712 17 күн бұрын
Beautiful Optimal approach. Thanks Striver!
@shashankyadav8977
@shashankyadav8977 3 ай бұрын
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
@LinhHoang-ml1qo Ай бұрын
but it takes more space complexity while the last solution of Striver only takes O(1)
@ujjawalchourasiya3988
@ujjawalchourasiya3988 8 ай бұрын
Aayla Jaado in 3rd approach Maja arha hai ab problems krne m . Thanks striver bhaiya for delivering such approaches things gets better and understandable ❤
@AkashRaj-vj6br
@AkashRaj-vj6br 7 ай бұрын
Thank you Striver for explaining so well...
@ashwaniagrawal27
@ashwaniagrawal27 9 ай бұрын
Timestamps Hashing Approach - 1:20 Length Difference Approach : 8:10 Optimal Approach- 16:25
@hat_awesome21
@hat_awesome21 11 ай бұрын
striver can we expect stack and queue from u next ?
@janaSdj
@janaSdj 11 ай бұрын
Yes please
@tonylee1868
@tonylee1868 11 ай бұрын
String much needed Stack and queue already there
@thorxn1382
@thorxn1382 3 ай бұрын
😢
@stith_pragya
@stith_pragya 6 ай бұрын
Understood.....Thank You So Much for this wonderful video..........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@AmanVerma-iu8jp
@AmanVerma-iu8jp 5 ай бұрын
the way you explain the concepts is lit🔥
@tanyaahuja7424
@tanyaahuja7424 11 ай бұрын
Thank you striver !!
@hareshnayak7302
@hareshnayak7302 7 ай бұрын
Wow Just wow what a mind blowing approch striver , Cool.thanks for this amazing video.
@TON-108
@TON-108 10 ай бұрын
After following playlist till here, now i'm able to do these question myself 🌚 Thank You Striver Bhaiya!!!
@navneetuppal9753
@navneetuppal9753 9 ай бұрын
Bro how are you able to think the approach and till which approach could you think of like till brute better or optimal and how?
@LukmaansStack
@LukmaansStack 8 ай бұрын
i was able to solve bruteforce but the 2nd and 3rd approches were out of my mind☹☹@@navneetuppal9753
@ankush8243
@ankush8243 10 ай бұрын
Thank you bro!💙 keep teaching like this💯🤗
@ShaikBanu-j2o
@ShaikBanu-j2o 4 ай бұрын
Third approach is mind blowing
@MohammadEhshan-ve6uz
@MohammadEhshan-ve6uz 2 ай бұрын
Done it in 5 lines: Node* first=head1;Node* second=head2; while(first!=second){ first=(first!=NULL) ? first->next : head2; second=(second!=NULL) ? second->next : head1; } return first;
@darshilmodi6851
@darshilmodi6851 5 ай бұрын
third approach is the real goat
@oyeesharme
@oyeesharme 3 ай бұрын
thanks bhaiya for providing such an amazing content
@ritikshandilya7075
@ritikshandilya7075 6 ай бұрын
Thankyou so much for great explanation @Striver
@knowthrvdo
@knowthrvdo 8 ай бұрын
NICE LECTURE AND PLZ UPLOAD REMAINING LECTURES OF A TO Z SDA SHEET PLZ THEY ARE VERY HELPFULL FOR US
@kushalswarup2662
@kushalswarup2662 5 ай бұрын
mind blowing method. cant believe woahh
@kushalkollu8628
@kushalkollu8628 5 ай бұрын
damn man! what an idea for the optimal approach
@anastasiiamaslova4220
@anastasiiamaslova4220 11 ай бұрын
great explanation!
@tejaspatel6965
@tejaspatel6965 2 ай бұрын
damn the third approach is beautiful
@prajapati-suraj
@prajapati-suraj 2 ай бұрын
if anyone does figure out the third approach on his own, he is a genius.........
@MohammadEhshan-ve6uz
@MohammadEhshan-ve6uz 2 ай бұрын
me
@piyushrawat4668
@piyushrawat4668 2 күн бұрын
damnn🔥🔥the third approach!!!
@utkarshpundeer07
@utkarshpundeer07 3 ай бұрын
3rd approach was a 🤯🤯
@vaibhavbhatt734
@vaibhavbhatt734 11 ай бұрын
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)
@ranjeetkumaryadav1837
@ranjeetkumaryadav1837 3 ай бұрын
Thanks sir Last one is 🔥🔥
@SHIVAMSINGHPARIHAR-w1i
@SHIVAMSINGHPARIHAR-w1i 2 ай бұрын
Was asked to me in Oracle Intern Technical Round 1 Interview
@prathameshjadhav2942
@prathameshjadhav2942 11 ай бұрын
So help full video
@hashtagcc
@hashtagcc 7 ай бұрын
The first time who have invented this algo must be from another dimension😙
@prathameshjadhav2942
@prathameshjadhav2942 11 ай бұрын
Nice teaching
@rohandas6298
@rohandas6298 4 ай бұрын
Why the time complexity of the last approach is not O(2 * (n1 + n2)) ??
@BhavanaReddy15
@BhavanaReddy15 4 ай бұрын
Same doubt
@Fe-ironman
@Fe-ironman 4 ай бұрын
@@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)
@NazeerBashaShaik
@NazeerBashaShaik 6 ай бұрын
Understood, thank you.
@selene8721
@selene8721 4 ай бұрын
Thank you so much!!
@pratyushtripathi1728
@pratyushtripathi1728 10 ай бұрын
Understood 😊
@kale-lb5pr
@kale-lb5pr 9 ай бұрын
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.
@manga_mania. 11 ай бұрын
thank you striver
@AlaskaAlaska-xq4gk
@AlaskaAlaska-xq4gk 4 ай бұрын
zeherrrrrrr teaching
@saswatrath4646
@saswatrath4646 7 ай бұрын
3rd approach was awesome haha
@DeepakPatel-d5v
@DeepakPatel-d5v 7 ай бұрын
Thanks a lot bhaiya
@harigs72
@harigs72 2 ай бұрын
Understood.🎉❤
@YourCodeVerse
@YourCodeVerse 9 ай бұрын
Understood✅🔥🔥
@DeadPoolx1712
@DeadPoolx1712 2 ай бұрын
UNDERSTOOD;
@ManishLakkavatri
@ManishLakkavatri 11 ай бұрын
Understood!
@Learnprogramming-q7f
@Learnprogramming-q7f 8 ай бұрын
Thank you Bhaiya
@SiddhesDas
@SiddhesDas 24 күн бұрын
small correction if (n1 < n2) { return collisionPoint(headB, headA, n2 - n1); } else { return collisionPoint(headA, headB, n1 - n2); } baaki first class
@ramkrishnapatil2105
@ramkrishnapatil2105 Ай бұрын
dimag hil gya bhai 🤐🤐
@khalasianiket816
@khalasianiket816 4 ай бұрын
understood ❤
@shelkeonka
@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-g9l
@HeetMungra-g9l 12 күн бұрын
hey!! what if we start traversing from end of the both list and return the last node where they are equal??
@hajeeramohamad7641
@hajeeramohamad7641 Ай бұрын
in the second approach - what if the length of both the linked lists is same? how will the collision function work then?
@NARUTOUZUMAKI-bk4nx
@NARUTOUZUMAKI-bk4nx 9 ай бұрын
Understooood
@Manjith-1887
@Manjith-1887 5 ай бұрын
mapm; while(headA!=nullptr) { m[headA]++; headA=headA->next; } while(headB!=nullptr) { if(m.find(headB)!=m.end()) { return headB; } headB=headB->next; } return nullptr;
@knight-z1x
@knight-z1x 4 ай бұрын
beautiful
@DEVANSHVYAS-z1b
@DEVANSHVYAS-z1b 4 ай бұрын
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { ListNode *p1 = headA, *p2 = headB; while(p1 != p2){ p1 = (p1 ? p1->next : headB); p2 = (p2 ? p2->next : headA); } return p1; }
@manikanta2000
@manikanta2000 12 күн бұрын
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; } }
@rishipatwa6823
@rishipatwa6823 2 ай бұрын
can we do like reverse both ll and then check them until they are equal ..once unequal return the prev node
@kale-lb5pr
@kale-lb5pr 9 ай бұрын
how does storing nodes directly make difference if we encounter same node value form second linked list why hashmap was showing no???/
@factswithjenny9
@factswithjenny9 9 ай бұрын
thanks
@chiragbansod8252
@chiragbansod8252 7 ай бұрын
understood
@ArpanChakraborty-do6yz
@ArpanChakraborty-do6yz 8 ай бұрын
Understand 31:53
@harshitjaiswal9439
@harshitjaiswal9439 9 ай бұрын
understood.
@akashumre22
@akashumre22 11 ай бұрын
Bro thanks
@nehapimpalkar396
@nehapimpalkar396 10 ай бұрын
understood!
@harshuke5831
@harshuke5831 11 ай бұрын
Understood
@SurajSharma-z9p
@SurajSharma-z9p 9 ай бұрын
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
@shivangairan6904
@shivangairan6904 9 ай бұрын
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-z9p
@SurajSharma-z9p 9 ай бұрын
@@shivangairan6904 Understood. Thanks
@harshuke5831
@harshuke5831 11 ай бұрын
Understood 30lakh
@fsyk1306
@fsyk1306 5 ай бұрын
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.
@aryasharma69
@aryasharma69 2 ай бұрын
Try with different example like N1=5 & N2= 7, then you will get to know why it fails
@RAHULSHARMA-on6tm
@RAHULSHARMA-on6tm 5 ай бұрын
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
@rahulnegi4027
@rahulnegi4027 2 ай бұрын
i would be simpler if these were circular h1->tail = h2 & h2->tail = h1;
@Chlo_Chle_Hum
@Chlo_Chle_Hum 3 ай бұрын
is circular linked list important?...if yes,from where to do..someone pls suggest
@LukmaansStack
@LukmaansStack 8 ай бұрын
striver bhai we need string please
@NonameNoname-f2t
@NonameNoname-f2t 8 ай бұрын
SUUUUUUUUPERRRRRRRRRBBBBBBBBBBB
@VineetChelani1304
@VineetChelani1304 11 ай бұрын
can we even compare each node of one LL to Other LL and get the first intersection ??
@dhrumilparmar1505
@dhrumilparmar1505 11 ай бұрын
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
@SuvamoySamanta-n2x Ай бұрын
why use this line mpp.find( temp) != mpp.end(); please explain this line
@SuvamoySamanta-n2x
@SuvamoySamanta-n2x Ай бұрын
!= use why
@roshnisingh7364
@roshnisingh7364 9 ай бұрын
please share the code for last approach
@ekjotsingh9609
@ekjotsingh9609 7 ай бұрын
Why wasn't a set used in the hashing approach? Wouldn't that be better?
@aryasharma69
@aryasharma69 2 ай бұрын
That will still take O(n) space
@kale-lb5pr
@kale-lb5pr 9 ай бұрын
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...
@lot2say590
@lot2say590 9 ай бұрын
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.
@djpro6413
@djpro6413 9 ай бұрын
@@lot2say590 Thanks bro same question arise to me
@stellar3496
@stellar3496 4 ай бұрын
waatha idhan da coding 🤯🤯
@naturesrevolution
@naturesrevolution 5 ай бұрын
anyone pls answer in second approach what happens if t1 and t2 contains same element before linking?
@qwerty20917
@qwerty20917 5 ай бұрын
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..
@naturesrevolution
@naturesrevolution 5 ай бұрын
@@qwerty20917 thank you bro
@utkarshsingh3319
@utkarshsingh3319 11 ай бұрын
❤❤
@jagadeeshp1163
@jagadeeshp1163 10 ай бұрын
what if we take 3->1 and 1-> it fails ??
@Shivi32590
@Shivi32590 5 ай бұрын
thank you!
@dhakerk094
@dhakerk094 10 ай бұрын
agar dono linked list me koi intesection point nhi hai to
@swapnil7142
@swapnil7142 24 күн бұрын
third option ke liye thought process rahega, ye dimag me kaise aayega
@kale-lb5pr
@kale-lb5pr 9 ай бұрын
pls explain my concern im just a beginner dont break my spirit like that!!!!!!!!!!!
@moksh455
@moksh455 10 ай бұрын
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
@moksh455
@moksh455 10 ай бұрын
ahh got it we need to add a check after we interchange temps with heads as well
@yourhonestbro217
@yourhonestbro217 5 ай бұрын
This question was not that difficult, my first approach was the optimal one
@SamyakSharma-oy1bv
@SamyakSharma-oy1bv 13 күн бұрын
respect++;
L13. Find the middle element of the LinkedList | Multiple Approaches
14:37
Who's spending her birthday with Harley Quinn on halloween?#Harley Quinn #joker
01:00
Harley Quinn with the Joker
Рет қаралды 27 МЛН
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 84 МЛН
World’s strongest WOMAN vs regular GIRLS
00:56
A4
Рет қаралды 45 МЛН
Sliding Window Technique - Algorithmic Mental Models
36:45
Ryan Schachte
Рет қаралды 361 М.
L14. Detect a loop or cycle in LinkedList | With proof and Intuition
20:26
Programming Languages Tier List 2024
16:18
Neal Wang
Рет қаралды 10 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 145 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Brian Will
Рет қаралды 2,1 МЛН
Microservices are Technical Debt
31:59
NeetCodeIO
Рет қаралды 635 М.
L25. Merge K Sorted Lists | Multiple Approaches
30:02
take U forward
Рет қаралды 51 М.
Who's spending her birthday with Harley Quinn on halloween?#Harley Quinn #joker
01:00
Harley Quinn with the Joker
Рет қаралды 27 МЛН