Intersection of Two Linked List | EP 18

  Рет қаралды 18,669

Fraz

Fraz

Күн бұрын

Lecture Notes: leadcoding.in/...
Watch the complete Linked List Series • Linked List Series
Coding Ninjas Courses 15 % OFF aff.codingninj...
Question (codestudio) bit.ly/39k7U1h
Question (leetcode) leetcode.com/p...
Placement Preparation Roadmap • Roadmaps for Placement
Hi, I am Fraz.
I am Software Engineer working at Curefit and I love teaching.
This is my Channel where I upload content related to Interviews and my personal experiences.
My contact details
Instagram :- / frazmohammad
Connect with me on LinkedIn :- / mohammad-f-bb4886157
Telegram Group t.me/LeadCoding

Пікірлер: 46
@kakadiazeel
@kakadiazeel 2 жыл бұрын
Leetcode discussion section is one of the best. Last solution is one of the most voted and appreciated solution. Kudos for your mathematical explainations also. 🌟
@kulkarnisoham
@kulkarnisoham Жыл бұрын
100% true
@TomShelbyXD
@TomShelbyXD 2 жыл бұрын
My mind is blown after seeing all these solutions for a single problem 🤯 and the last solution 💯
@Snehanomics
@Snehanomics 2 жыл бұрын
Bhaiya one thing I will appreciate in you that you are so so so humble and a calm teacher! You teach so well !
@mohammadfraz
@mohammadfraz 2 жыл бұрын
Thank you so much
@pranabnandy450
@pranabnandy450 2 жыл бұрын
You can add one more approach.............. >> first traverse the List1 to end..... >> then make temp1 -> next = head1 >> Then use slow Fast pointer concept to detect loop in a linked list >> If it exist store the node in a separate pointer ( target = slow ) >> If it does not exist then ( target=NULL) >> Lastly again traverse the List1 and make last node point to NULL ( temp1->next = NULL) Correct me if I am wrong.
@pawansingh7430
@pawansingh7430 2 жыл бұрын
In the unordered set Approach We have to work on nodes and not on the values. So even if values inside the node is same the nodes maybe different because of their next pointer, so we don't check for values So we will create Set and not Set
@krishnaradhey2814
@krishnaradhey2814 2 жыл бұрын
Bro do cover all the DS topics step by step
@mohammadfraz
@mohammadfraz 2 жыл бұрын
Will try
@chirag488
@chirag488 Жыл бұрын
After 15 minutes of trying , I found the most optimized approach as told in the video. Thanks Fraz bhaiya :)
@rishisrivastava4878
@rishisrivastava4878 Жыл бұрын
Bhai aap bht acha video bnate Dil se bol rha hu abb jb bhi recommend krta hai aaka ya striver ya babbar I always choose you❤ itna asan code rhta hai ki fat se yaad ho jaata hai❤
@keshavgaur4535
@keshavgaur4535 2 жыл бұрын
the last approach was awesome 💥
@mohammadfraz
@mohammadfraz 2 жыл бұрын
Thanks a lot Keshav for supporting
@keshavgaur4535
@keshavgaur4535 2 жыл бұрын
@@mohammadfraz welcome bhaiya 😇
@sanjanachandravanshi9864
@sanjanachandravanshi9864 2 жыл бұрын
@@keshavgaur4535 what is time complexity of last approach?
@mdnadeem6343
@mdnadeem6343 2 жыл бұрын
Op bhaiya last approach was lit 🔥 I was thinking that bs Itna hi likhna tha 😅😅.....I like the way you convert every solution into a simple and sober equation thanks bhaiya ❣
@mohammadfraz
@mohammadfraz 2 жыл бұрын
Thank you so much 😀
@DipsOfficial802
@DipsOfficial802 Жыл бұрын
Thank you so much bhaiya for such a great solution thanks🙏🙏🙏
@deepurana6010
@deepurana6010 Жыл бұрын
You are amazing bhaiya❤. Loved the way u teach
@tech_wizard9315
@tech_wizard9315 2 жыл бұрын
By when you will upload entire playlist?😍
@mohammadfraz
@mohammadfraz 2 жыл бұрын
As soon as possible
@surendrababu223
@surendrababu223 Жыл бұрын
Understood
@anishbishnoi29xD
@anishbishnoi29xD 2 жыл бұрын
Sir thanks for video. Please Continue More Java DSA
@maaltez
@maaltez 2 жыл бұрын
Bhaiya aapka content ek number h, i just want one more help i am looking for good headphones and not able to make decision. Can you please suggest which headphones are you using.
@kale-lb5pr
@kale-lb5pr 7 ай бұрын
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; } cout
@thomanani6826
@thomanani6826 2 жыл бұрын
Nice explanation brother
@vagabondfoodie5788
@vagabondfoodie5788 Жыл бұрын
Bhaiya what is the tc and space complexity of last approach?
@shamimsarker839
@shamimsarker839 Жыл бұрын
Best
@desihiphop4998
@desihiphop4998 2 жыл бұрын
Bhaiya 1 approach strike krgyi thi wo length waali baaki uske agli waali to katiye 🔥🔥 thi maja aagya !!!!!!!!!!
@mohammadfraz
@mohammadfraz 2 жыл бұрын
❤️❤️ bhai apna naam to batao Talha Yunus
@desihiphop4998
@desihiphop4998 2 жыл бұрын
@@mohammadfraz bhaiya Himanshu Joshi telegram pe महाराज ke naam se hun dono jagah pareshaan krta hun aapko Comment kr kr ke 😂
@mohammadfraz
@mohammadfraz 2 жыл бұрын
Maharaj is for muhfaad?
@desihiphop4998
@desihiphop4998 2 жыл бұрын
@@mohammadfraz Haan bhaiya
@18devpratapsingh33
@18devpratapsingh33 Жыл бұрын
C++ Solution using unordered_Set class Solution { public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { unordered_set s; ListNode* temp = headA; while(temp!=NULL){ s.insert(temp); temp = temp->next; } ListNode* temp2 = headB; while(temp2!=NULL){ if(s.find(temp2)!=s.end()){ return temp2; } temp2 = temp2->next; } return NULL; } };
@yashbahuguna8135
@yashbahuguna8135 2 жыл бұрын
you didn't discussed the stack approach
@18devpratapsingh33
@18devpratapsingh33 Жыл бұрын
Brute Force Approach class Solution { public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { ListNode* tempB = headB; while(headA!=NULL){ while(tempB!=NULL){ if(tempB==headA) return headA; tempB = tempB->next; } tempB = headB; headA = headA->next; } return NULL; } };
@vaidanshkukreja8970
@vaidanshkukreja8970 2 жыл бұрын
BRUTE FORCE APPROACH : ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { ListNode * temp1 = headA; ListNode * temp2 = headB; if(temp1==NULL || temp2==NULL) return NULL; while(temp1!=NULL || temp2!=NULL) { temp1 = headA; if(temp1 == temp2) return temp1; else { temp1 = temp1->next; while(temp1!=NULL) { if(temp1 == temp2) return temp1; temp1 = temp1->next; } temp2 = temp2->next; } } return NULL; } ---------------------------------------------------------------- MAYBE: Time Complexity : O(n*m) Space Complexity : O(1) Any doubts related to the code ping me happy to help 😀
@shyaamaltripathi5373
@shyaamaltripathi5373 2 жыл бұрын
Bhaiyya jo aapne doosra wala solution bataya tha usmein unordered set wala usmein agar kisi ek point pe dono list mein same elements hain but lists are not intersecting tab kaise hoga ?
@pawansingh7430
@pawansingh7430 2 жыл бұрын
We have to work on nodes and not on the values. So even if values inside the node is same the nodes maybe different because of their next pointer, so we don't check for values So we will create Set and not Set
@shyaamaltripathi5373
@shyaamaltripathi5373 2 жыл бұрын
@@pawansingh7430 Ok thank you
@SunnyGupta00
@SunnyGupta00 2 жыл бұрын
Reach++
@pranavkorhale5089
@pranavkorhale5089 2 жыл бұрын
//2nd approach public class Solution { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { ListNode temp1 = headA; ListNode temp2 = headB; int count1 = 0; while(temp1!=null) { count1++; temp1 = temp1.next; } int count2 = 0; while(temp2!=null) { count2++; temp2 = temp2.next; } temp1 = headA; temp2 = headB; if(count1count2) { int diff = count1-count2; while(diff!=0) { temp1 = temp1.next; diff--; } } while(temp1!=null) { if(temp1==temp2) { return temp1; } temp1 = temp1.next; temp2 = temp2.next; } return null; } }
@Sonu-tg6tg
@Sonu-tg6tg 2 жыл бұрын
Please make videos using JAVA
@nishantparaskar2048
@nishantparaskar2048 Жыл бұрын
public ListNode getIntersectionNode(ListNode headA, ListNode headB) { ListNode a = headA ; ListNode b = headB ; while(a!= b) { if(a == null) { a = headB ;} else {a =a.next ; } if(b == null) { b= headA ;} else { b= b.next ;} } return a ; // or b } i took the reference from this video and did this
@parthrastogi572
@parthrastogi572 Жыл бұрын
Isse kharab bhi koi padha sakta hai kya!! Poor explanation Don't watch this video!!
Tier 3 to Google 40LPA | 2024 Batch Pass Out
26:44
Fraz
Рет қаралды 40 М.
So Cute 🥰
00:17
dednahype
Рет қаралды 55 МЛН
Секрет фокусника! #shorts
00:15
Роман Magic
Рет қаралды 112 МЛН
LRU cache | EP 22
19:51
Fraz
Рет қаралды 24 М.
Reverse Linked List | EP 10
22:27
Fraz
Рет қаралды 35 М.
Remove Linked List Elements | EP 20
12:50
Fraz
Рет қаралды 18 М.
Middle of the Linked List | EP 5
9:24
Fraz
Рет қаралды 35 М.
Remove Duplicates from Sorted List | EP 15
9:50
Fraz
Рет қаралды 18 М.
Reverse Nodes in k-Group (NO EXTRA SPACE) | EP 12
19:51
So Cute 🥰
00:17
dednahype
Рет қаралды 55 МЛН