No video

Intersection point of two Linked Lists | Amazon | Microsoft | Brute | Better | Optimal1 | Optimal2

  Рет қаралды 161,695

take U forward

take U forward

Күн бұрын

Check our Website:
In case you are thinking to buy courses, please check below:
Link to get 20% additional Discount at Coding Ninjas: bit.ly/3wE5aHx
Code "takeuforward" for 15% off at GFG: practice.geeks...
Code "takeuforward" for 20% off on sys-design: get.interviewr...?_aff=takeuforward
Crypto, I use the Wazirx app: wazirx.com/inv...
Take 750 rs free Amazon Stock from me: indmoney.oneli...
Earn 100 rs by making a Grow Account for investing: app.groww.in/v...
Linkedin/Instagram/Telegram: linktr.ee/take...
--------------------------------------------------------------------------------------------------------------------------------------------------- ✅This is where I teach: ---- Use coupon-code "TAKEUFORWARD" for getting 10% on my course at GFG: bit.ly/striver_...
I have decided to make a free placement series comprising of video lectures(C++ and Java) on the entire SDE sheet.. ✅(bit.ly/takeUfo...) ..
✅Use coupon-code "TAKEUFORWARD" for getting 10% for all GFG courses: bit.ly/tuf_gfgC...
✅Entire Series: bit.ly/placemen...
✅Problem link: leetcode.com/p...
If you appreciate the channel's work, you can join the family: bit.ly/joinFamily
Thumbnail Creator: / rikonakhuli
✅ Striver's Linkedin Profile: / rajarvp
✅ Instagram: / striver_79
Connect with us: t.me/Competiti... (Use Link in Mobile only, if not works search "takeUforward" in telegram)..
#dsa #leetcode #placements

Пікірлер: 239
@takeUforward
@takeUforward 3 жыл бұрын
Understooooooooooooooood? . Instagram(connect to know closely about updates): instagram.com/striver_79/ . . If you appreciate the channel's work, you can join the family: bit.ly/joinFamily
@sagardas4569
@sagardas4569 3 жыл бұрын
Your voice has changed i think...
@gautamsuthar4143
@gautamsuthar4143 3 жыл бұрын
11:01 How is it O(M). It should be O(M+N) according to me because we can't traverse both pointers simultaneously. Please reply
@dennyage4791
@dennyage4791 2 жыл бұрын
Understood
@nullvoid7543
@nullvoid7543 2 жыл бұрын
Yesss sir
@rahulnegi4027
@rahulnegi4027 Жыл бұрын
thanks bhaiya
@p61800
@p61800 3 жыл бұрын
Thanks for this explanation! Please don't stop this ever, best thing on Internet.
@takeUforward
@takeUforward 3 жыл бұрын
Glad :)
@subirkumar6786
@subirkumar6786 Жыл бұрын
Brute approach - 1:23 Better approach - 3:04 Optimal 1 - 7:15 Optimal 2 - 12:05
@anupamayadav7038
@anupamayadav7038 3 жыл бұрын
best explaination ... Linkedlist was a kind of nightmare for me but now your tutorials are making it is easy ..and simple for me. Thankyou.
@RV-qf1iz
@RV-qf1iz Жыл бұрын
I liked the hashing approach as it is very easy to code:- public ListNode getIntersectionNode(ListNode headA, ListNode headB) { Mapmap=new HashMap(); ListNode t1=headA; while(t1!=null){ map.put(t1,t1.val); t1=t1.next; } ListNode t2=headB; while(t2!=null){ if(map.containsKey(t2)){return t2;} t2=t2.next; } return null; }
@anurondas3853
@anurondas3853 Жыл бұрын
Sadly it may not be the case with the interviewer.
@RV-qf1iz
@RV-qf1iz Жыл бұрын
@@anurondas3853 why we cannot use hashmap in an interview ?
@pranav288
@pranav288 Жыл бұрын
@@RV-qf1iz extra space is not good
@jatinukey4062
@jatinukey4062 9 ай бұрын
​@@RV-qf1izthey will ask to optimize the space complexity 😅
@omhari8297
@omhari8297 2 жыл бұрын
Thanks for the video... One more approach if we are allowed to change the value of nodes:- ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { ListNode *x=headA; while(x!=NULL) { x->val=x->val-1000'000'001; x=x->next; } ListNode *ans=NULL, *y=headB; while(y!=NULL) { if(y->valnext; } x=headA; while(x!=NULL) x->val+=1000'000'001, x=x->next; return ans; }
@paragsaini2795
@paragsaini2795 3 жыл бұрын
Another approach we can try is Just make tail_node -> next, points to one of the head, and now the problem reduce to the detecting the cycle in linked list. And at last modify tail_node->next to nullptr to obtain the original linked lists
@yatinarora1252
@yatinarora1252 3 жыл бұрын
In this question there is mentioned there is no cycle in linked list
@justarandomguy6106
@justarandomguy6106 2 жыл бұрын
Good observation
@virusnetic
@virusnetic 2 жыл бұрын
@@yatinarora1252 you can just make a cycle by updating tail_of_first_ll.next = head_of_first_ll and revert it back.
@himanshumaurya428
@himanshumaurya428 Жыл бұрын
@@virusnetic you are not allowed to change the structure of LL.
@sourabhkumar5815
@sourabhkumar5815 10 ай бұрын
That's a very creative approach. but it won't cover the case when there is no merge point.
@_-6912
@_-6912 3 жыл бұрын
I'm happy actually, first best solution was something even I came up the first time when I was doing this question.
@jaskiratsinghosahan4638
@jaskiratsinghosahan4638 3 жыл бұрын
Best DSA series on whole KZfaq🔥🔥
@lokeshvikram6192
@lokeshvikram6192 3 жыл бұрын
You are helping me a lot to get trained for placements bro. I am waiting for your next videos.i would be happy if you could complete this placement series as soon as you can because iam following your SDE sheet only bro.
@pranav288
@pranav288 2 жыл бұрын
hey did only doing sde sheet work for you ? how was your interview experience ?
@tg62672
@tg62672 Жыл бұрын
@@pranav288 well he didn't replied but what about you? did the sheet helped you?
@pranav288
@pranav288 Жыл бұрын
@@tg62672 I cracked the very first interview I appeared for. Still looking for more opportunities, will keep you posted.
@abhivarma1756
@abhivarma1756 Жыл бұрын
@@pranav288 update please
@viveksingh_01
@viveksingh_01 Жыл бұрын
@@pranav288 any updates?
@savalalingeshreddy6750
@savalalingeshreddy6750 3 жыл бұрын
thanks for the video bro good explanation keep doing!!! 3 methods--- {1}-1st Method- --------------- #include #include using namespace std; void insertFront(int d); struct Node{ int data; Node *next; Node(int x){ data = x; next = NULL; } }; Node* insertEnd(vector a,Node *head){ struct Node *dup = NULL; for(int i=0;inext = temp; dup = temp; } return head; } Node *intersectionOfLinkedList(Node *h1,Node *h2){ Node *temp = h2; while(h1 != NULL){ while(h2 != NULL){ if(h1 == h2) return h1; h2 = h2->next; } h1 = h1->next; h2 = temp; } return h1; } int main(){ struct Node *head1 = NULL; struct Node *head2 = NULL; vector a{1,3,4,5,6,7,187}; vector b{34,3,54,67,6,6,6,234}; head1 = insertEnd(a,head1); head2 = insertEnd(b,head2); Node *p = head2; Node *hd1 = head1; Node *temp = NULL; while(head1 != NULL){ if(head1->data == 3){ temp = head1; break; } head1 = head1->next; } while(head2->next != NULL) head2 = head2->next; head2->next = temp; Node *ans = intersectionOfLinkedList(hd1,p); cout
@manikanth.8507
@manikanth.8507 3 жыл бұрын
Great Work
@pendyalaabhishek8866
@pendyalaabhishek8866 2 жыл бұрын
i have a doubt in second why will both linked list have a node at same address ? it is possible that only the intersection vales are same but address is different so that mean 2nd method is wrong . ex 1->2->3->4->5->NULL; 10->11->3->4->5->NULL; if we take these 2 linked lists 3->4->5->NULL is the intersection but node 3 will have different address in both of the lists so 2nd method is wrong .
@Jack-mc7qe
@Jack-mc7qe 2 жыл бұрын
@@pendyalaabhishek8866 nope we dont have to separate nodes having same values we have to separate nodes with same address and on the top of that if their addresses are same then their values will also be same But its possible to have same values at 2 diff address but that wont be intersection point
@joseph2073
@joseph2073 2 жыл бұрын
legend dude
@dipakraut6058
@dipakraut6058 3 жыл бұрын
The second approach was just Amazing.
@bhaveshkumar6842
@bhaveshkumar6842 2 жыл бұрын
Correct me if I'm wrong. The hashing solution will have a space complexity of O(m+n). We have to consider the case where there's no intersection. So, we will add the addresses of all the nodes of the first list to the hash set and we will also have to add the addresses of all the nodes of the second list to the set since there is no common node.
@anshumaan1024
@anshumaan1024 Жыл бұрын
no, simply store the all nodes of first list, for second list you don't need to store the nodes, simply traverse each node of second list and check if they were in the hash table or not, if the node of second list is already in the set then, it means it the intersecting node, So, TC-> O(m+n) SC -> O( m), if m is the size of first list
@joydeb8202
@joydeb8202 3 жыл бұрын
Love your Videos............ Following this series since 2weeks .......... You are inspiration dude..... ; ) Get well sooooooooon...waiting for your comeback... take rest
@abhay9994
@abhay9994 9 ай бұрын
I wanted to send you a heartfelt thank you for your tireless dedication to teaching DSA for free. Your selflessness and passion for helping students with their job interview preparation have made a significant impact on my life and countless others. I am incredibly grateful for the knowledge and confidence you have imparted to us. Thank you for everything you do!❣✨✨
@pranshumehta3228
@pranshumehta3228 2 жыл бұрын
Time complexity of 2nd optimal solution would be O(m+n) in worst case Isn't it?
@JyotiSharma-wb1vy
@JyotiSharma-wb1vy 11 ай бұрын
Wow, this video is pure gold! 🌟 One of the best explanations I've come across, and it's not just about the brute force to optimized approach, but also the deep intuition behind it. I absolutely loved it! 👏 Thanks for breaking it down so clearly!
@positivity5358
@positivity5358 3 жыл бұрын
I don't know why but I really like your voice 😍( with that bengali accent touch).... Can't tell about the content where you teach because I am in 12th standard only 😉...But I know you are doing great things to make a remarkable change in college student by shaping their carrier...I know you have a job but you are selfless enough to guide students....Kudos to you bhaiya...
@takeUforward
@takeUforward 3 жыл бұрын
But am not a bengali XD
@positivity5358
@positivity5358 3 жыл бұрын
@@takeUforward I know that well but still that could be because you may have lived in Bengal that why....🙂🙂
@deepak9365
@deepak9365 3 жыл бұрын
bro you did one mistake a=a==null ?headB:a.next; b=b==null?headA:b.next; your code working fine also but it take more time on leetcode but after changing this line it will take less time to excute anyway thanks bro keep it up :)
@aditinagda6609
@aditinagda6609 2 жыл бұрын
One of the approach could be to create a set of Nodes, place first linkedlist nodes into that set, then start traversing the second linkedlist, the moment, we find set already contains that node, we return that node. And in the very last simply return the null.
@jatinukey4062
@jatinukey4062 9 ай бұрын
Yeah this approach will work also
@user-pf5mf6nu3u
@user-pf5mf6nu3u 10 ай бұрын
wow!!!!!! Amazing solutions. I hope one day I will be able to solve like this.
@siddharthjadav5025
@siddharthjadav5025 2 жыл бұрын
Python Solution: l1, l2 = head1, head2 while l1!=l2: if l1==None: l1=head2 if l2==None: l2=head1 l1=l1.next l2=l2.next return l1.data
@udayjordan4262
@udayjordan4262 2 жыл бұрын
basically you can also use hashmap if interviewer doesnt ask you space optimize it more .i mean constant space.
@ayushshukla1597
@ayushshukla1597 3 жыл бұрын
Even the interviewer would not know about the 2nd Optimal Solution. Amazing work.
@factfactorial632
@factfactorial632 2 жыл бұрын
Great Explanation Bhaiya I think TC of last solution should be O(m+n) correct me if I am wrong
@manistrikes
@manistrikes 2 жыл бұрын
No ,consider 2 linked list which are not intersecting...then u would had to traverse the bigger list twice in that case ...so the TC is 2×m
@rishikeshpawar3230
@rishikeshpawar3230 Жыл бұрын
Thanks !! Great explanation. Though I think among optimized approaches #1 and #2, the #1 is would be faster, as traversing each of linked list once only. For #2, your are traversing both lists, twice.. Still the #2 intuition was great.
@ranasauravsingh
@ranasauravsingh 2 жыл бұрын
UNDERSTOOD... !!! Thanks, striver for the video... :)
@mahithareddymaram4516
@mahithareddymaram4516 3 жыл бұрын
The explanation is super easy to understand. Thanks !! keep up the good work
@reassume4826
@reassume4826 2 жыл бұрын
Mind-blowing moment @13:17
@techykush7192
@techykush7192 3 жыл бұрын
wow amazing explanation love u bhaiya keep it up thanks a lot 😍😍
@toshanverma1084
@toshanverma1084 3 жыл бұрын
second approach is just wow. Thankyou.
@kaushikramabhotla4635
@kaushikramabhotla4635 3 жыл бұрын
the second optimal approach is 🔥🔥 !!! aag laga di bhai :)
@hariprasadsa8263
@hariprasadsa8263 2 жыл бұрын
In Optimal 2 Answer I was astonished by the way you have shown us to solve...Keep going man!
@surajsarmahpathak926
@surajsarmahpathak926 Жыл бұрын
Very imp concept. Thanks Striver !
@jatinkumar4410
@jatinkumar4410 10 ай бұрын
Amazing approach, amazing explanation
@nishantingle1438
@nishantingle1438 2 жыл бұрын
Best thing is the explanation rather than the code. You're awesome.
@jitendrapal4216
@jitendrapal4216 Ай бұрын
Your explanation is great ❤
@little-by-little-one-trave1770
@little-by-little-one-trave1770 2 жыл бұрын
Great explanation. But will the last concise optimal solution run if they do not have intersection ?
@jayuchawla1892
@jayuchawla1892 2 жыл бұрын
no 😫
@oqant0424
@oqant0424 3 жыл бұрын
after your hint i coded it myself..your logic explanation is very gd
@tannukumari5144
@tannukumari5144 3 жыл бұрын
The 2nd optimal approach is 🔥, Get well soon bhaiya..waiting for your next message on telegram just after posting new video :)
@Ashwani_sharma
@Ashwani_sharma Жыл бұрын
Last approach will not work when no intersection, stuck in while loop
@starboy415
@starboy415 Жыл бұрын
if(a==NULL && b==NULL) return -1; add this statement at the last in the while loop and it should work
@way2prosperity
@way2prosperity 9 ай бұрын
when will the loop break if the linked lists don't intersect according to best optimal 2nd solution? the condition d1!=d2 in while loop, will it result in an infinite loop in this case? i cant understand. will you explain?
@definitelyacat
@definitelyacat 3 жыл бұрын
how on earth do you think out such solutions?
@saurabhahuja6707
@saurabhahuja6707 2 жыл бұрын
Can we dirty node by adding one more member visitedcount by doing so ,,, we can iterate on first linked list and update visited to 1 then traverse second linked list. And if we found alrrady visited 1 then this is the intersection point ....complexity is o(m+n)
@prestoX
@prestoX 11 ай бұрын
Beautiful explanation.
@oqant0424
@oqant0424 3 жыл бұрын
THANKS VAEYA..EXPLAINED IT REALLY WELL..I WAS STUCK AT THIS PROBLEM FOR 3 DAYS...SAW MANY VIDEOS.....GOT NOTHING..THEN SAW YOUR VIDEO...GOT EVERY THING ..AND MOST IMPORTANTLY WHERE I WAS MAKING ERROR...THANK U SO MUCH VAEYA FROM THE BOTTOM OF MY HEART
@mayankraj5690
@mayankraj5690 Жыл бұрын
Method 2 solution C++ : . . . . ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { ListNode *tempa = headA,*tempb = headB; int count1=0,count2=0; while(tempa!=NULL){ tempa = tempa->next; count1++; } while(tempb!=NULL){ tempb = tempb->next; count2++; } int n = count2-count1; if(ncount2)?headA:headB; ListNode *temp2 = (count1next; n--; } while(temp1!=NULL){ if(temp1==temp2) return temp1; temp1=temp1->next; temp2=temp2->next; } return NULL; }
@hackpiece3094
@hackpiece3094 3 жыл бұрын
Thank you so much ❤️ Keep up the good work brother😁
@ytg6663
@ytg6663 2 жыл бұрын
Coming to last solution, wont it stuck in loop if no intersection found ???
@AB-tp9eg
@AB-tp9eg 2 жыл бұрын
Happy new year bhaiya, I have one doubt please answer, In the last you mentioned two optimal sol. of same complexity. Should we answer only last one or both optimal sol. in an interview? And bhaiya i think the complexity of last one optimal sol. is O(N+(M-N)+N) i.e. O(N+M) [in the worst case] where N->is smaller LL & M->is longer LL. Please explain
@iamparitosh
@iamparitosh 3 жыл бұрын
Another way can be with Stack; We push all the elements in both stack and pop() till we arrive at the same Node
@sarcaastech
@sarcaastech 3 жыл бұрын
that would take extra space .. so it wont be the best approach
@shivyanshgarg
@shivyanshgarg 2 жыл бұрын
What if we reverse the linked list and then traverse until both the nodes are same, and as soon as they are different, we output the previous node? Can anybody tell about this approach?
@dhirenparekh2646
@dhirenparekh2646 Жыл бұрын
It is not good because for case 1: where you are reversing the list by changing the next pointer of each node to previous. Here as you are modifying the given input, interviewer will be not happy. Also for pointing intersecting node to previous node, cannot be possible as there are two node previous it for two different linked list. This is of no use. case 2: where you are using extra space for creating a copy of reversed linked list. As this uses extra space, this is also not recommended when you can solve the same problem with constant space.
@subhajeetchakraborty1791
@subhajeetchakraborty1791 2 жыл бұрын
wow 2nd best approach was similar to hare and tortoise method
@ayanagrawal
@ayanagrawal 3 жыл бұрын
Can anyone please tell how is the case of no intersection handled in the last approach...
@samstar9777
@samstar9777 3 жыл бұрын
well, at the end of second iteration, both of the nodes will be equal to NULL and therefore equal to each other thus eventually terminating the while loop
@shreyasingh1258
@shreyasingh1258 3 жыл бұрын
The way you explain really helps alott!!!thanks bhaiya🙌
@takeUforward
@takeUforward 3 жыл бұрын
Glad to hear that
@yogeshvaishnav6464
@yogeshvaishnav6464 3 жыл бұрын
Striver! I didn't get one thing in the 2nd best approach... How did this loop breaks when there is not intersection point and list1 is shorter than list2? while(a != b){ a = (a == NULL) ? head2 : a->next; b = (b == NULl) ? head1 : b->next; } why didn't this go to infinite loop? as a and b gets interchanged on reaching NULL and starting it all over again but from the other list this time.
@yogeshvaishnav6464
@yogeshvaishnav6464 3 жыл бұрын
Okay got this! At one point both becomes of same length and head towards the intersection point (or NULL if there is no intersection). Thanks for the video. dudho nahao futo falo !😂
@takeUforward
@takeUforward 3 жыл бұрын
They will start moving together and they will reach null at sane time. Take an example u will understand. If they reach null at same time, its over.
@nileshsinha7869
@nileshsinha7869 3 жыл бұрын
I just solved this question last night. Amazing explanation
@takeUforward
@takeUforward 3 жыл бұрын
Glad it helped!
@alokkumar-ki7wp
@alokkumar-ki7wp 2 жыл бұрын
Love you Striver!! What a code that was of 2nd optimal solution.
@user-dv3of6ji9e
@user-dv3of6ji9e Жыл бұрын
The best explanation. Thank you
@venkatsaireddy1412
@venkatsaireddy1412 6 ай бұрын
I like the technique♥
@AmarjeetKumar-to9ub
@AmarjeetKumar-to9ub Жыл бұрын
Thank You :)
@rtm4829
@rtm4829 2 жыл бұрын
In the C++ code if there is no intersection point in LL how will a== b (To stops while loop)??
@calmyourmind5617
@calmyourmind5617 2 жыл бұрын
" Obviously the interviewer will not be happy and he will ask you to optimize the approach" - has a separate fanbase.
@rounakpattanayak6816
@rounakpattanayak6816 2 жыл бұрын
2nd optimal soln is faulty I guess ...if there is no insertion point I think 2nd soln will not work
@manistrikes
@manistrikes 2 жыл бұрын
It will work....if both of them are non intersecting......at one point while traversing...u will be reaching null from both lists..and u will be returning null....make one test case and try...it will work
@ericcartman4799
@ericcartman4799 3 жыл бұрын
can also be done in a straightforward way using stack. The idea is to create two stacks and push the address of both lists in it. The compare element of the stack and start popping, whenever we didn't find the match break. Time complexity O(N) + O(M) + O(M+N; Code: int intersectPoint(Node *head1, Node *head2) { stack s1; stack s2; Node *curr1 = head1; Node *curr2 = head2; while (curr1 != NULL) { s1.push(curr1); curr1 = curr1->next; } while (curr2 != NULL) { s2.push(curr2); curr2 = curr2->next; } int y = -1; while (!s1.empty() && !s2.empty()) { if (s1.top() == s2.top()) { y = s1.top()->data; s1.pop(); s2.pop(); } else { break; } } return y; }
@takeUforward
@takeUforward 3 жыл бұрын
bro, it takes extra space, thats gonna get you rejected in interview, so optimise everything
@ericcartman4799
@ericcartman4799 3 жыл бұрын
@@takeUforward Yes...thanks for that
@cricwhiz151
@cricwhiz151 Жыл бұрын
nice explaination thank you
@naro.tam_
@naro.tam_ 2 жыл бұрын
I was able to code 1st optimal by myself but 2nd one was jusssss great
@vineetjadhav1785
@vineetjadhav1785 17 күн бұрын
Its similar to hare and tortoise method
@anushak1446
@anushak1446 Жыл бұрын
understood thank you
@heyrmi
@heyrmi 3 жыл бұрын
Bhaiya I am late. But I am glad I here.
@paragroy5359
@paragroy5359 3 жыл бұрын
Nice explanation sir......thanks for the playlist extremely helpful...
@jaswantrohila3776
@jaswantrohila3776 3 жыл бұрын
What a solution 🔥🔥 didn't thought of this....thanks
@soummodipsaha5363
@soummodipsaha5363 3 жыл бұрын
How to find the length of 2 lists simultaneously in Optimal 1 ??
@gautamsuthar4143
@gautamsuthar4143 3 жыл бұрын
11:01 How is it O(M). It should be O(M+N) according to me because we can't traverse both pointers simultaneously. Please reply.
@chowmein1397
@chowmein1397 3 жыл бұрын
It will be O(M) if M>N, else it will be of O(N) We can traverse both of them together by using if conditions in loop while(temp1!=NULL || temp2!=NULL) { if(temp1!=NULL) { l1++; temp1=temp1->next; } if(temp2!=NULL) { l2++; temp2=temp2->next; } } temp1 and temp2 are dummy nodes of list 1 and list 2
@gautamsuthar4143
@gautamsuthar4143 3 жыл бұрын
@@chowmein1397 thanks. I appreciate it.
@aryansinha1818
@aryansinha1818 Жыл бұрын
12:20 Optimized Solution
@vidhi_bhatt
@vidhi_bhatt 2 жыл бұрын
Beautifully explained!!
@_hulk748
@_hulk748 Жыл бұрын
understood sir ji🙏🙏
@aaryansingh3783
@aaryansingh3783 2 жыл бұрын
Is the dummy node as mentioned by bhaiya same as pointer to a Node (head of linked list) like Node * temp = head
@kale-lb5pr
@kale-lb5pr 6 ай бұрын
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
@praharshsingh2095
@praharshsingh2095 3 жыл бұрын
How will the third approach work is the abs(length1 - length2) is equal to 1? Ex - 1 2 8 2 2 1 8 9 9 both pointer will move one at a time and will never meet
@takeUforward
@takeUforward 3 жыл бұрын
It will never meet because the test case is wrong. It should have been 1,2,8,2,2 1,8,2,2
@abdurrahaman388
@abdurrahaman388 3 жыл бұрын
Could we able to solve this by reversing both link list and then traverse from back ?
@abhishekjha5651
@abhishekjha5651 3 жыл бұрын
It is mentioned in the question that, you cannot change the original structure of the linked list.
@priyanshunandan9648
@priyanshunandan9648 3 жыл бұрын
@@abhishekjha5651 usko v pata hoga, but usko reverse karke karna hoga. Wtw abdur yes we can do it. You just have to call reverse functions two times for list1 and list2 and now you can perform the same operation you will get the same answer. The point of intersection won't change even after reversing.
@vishalgowrav
@vishalgowrav 2 жыл бұрын
a=a==null ?headB:a.next; b=b==null?headA:b.next; Can anyone please explain what does it mean?
@sulthanmogal9692
@sulthanmogal9692 2 жыл бұрын
if(a == null) a = headB; else a = a.next; if(b == null) b = headA; else b = b.next;
@vishalgowrav
@vishalgowrav 2 жыл бұрын
@@sulthanmogal9692 Thank u so much! :-)
@khageshbansal2400
@khageshbansal2400 2 жыл бұрын
Wouldn't your algo return wrong answer of 1 at 16:11 because head a and head b have same values.
@niyom8866
@niyom8866 Жыл бұрын
ANSWER COMES RIGHT., BUT I HAVE SAME DOUBHT
@anchitmittal6546
@anchitmittal6546 2 жыл бұрын
Very Well Explained. Thanks Mate 👍
@ketankhandelwal8626
@ketankhandelwal8626 3 жыл бұрын
bro i just wanna know one thing do u crack all this intutions by yourself or have seen somewhere or it just came by practice? ..
@programmertik2046
@programmertik2046 2 жыл бұрын
first i like your videp then i watch it !!
@pratikvyas3384
@pratikvyas3384 3 жыл бұрын
how common node is different from intersection node? like i can see there is '1' common in both the llist, then why we are considering 8 as the intersecting node? can anyone please explain me?
@jobanpreetsingh2370
@jobanpreetsingh2370 3 жыл бұрын
In the problem we are actually finding the intersection point and after that point the both list have same nodes till tail (end) of both lists. 1 is common to both but not a intersection point because after 1 the lists don't have same nodes. While after 8 they have same nodes till the end. 😊😊
@tarunraheja84
@tarunraheja84 2 жыл бұрын
give code of all the approaches shown
@deependu__
@deependu__ 2 жыл бұрын
Awesome. Thanks.
@codedroidfun9398
@codedroidfun9398 2 жыл бұрын
Thankyou vaiya for such an awesome explanation
@gautamsuthar4143
@gautamsuthar4143 3 жыл бұрын
Please tell me the time complexity of this solution. and what will be the time complexity if I use unordered set? ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { ListNode *p=headA; ListNode *q=headB; set s; while(p){ s.insert(p); p=p->next; } while(q){ if(s.find(q)!=s.end()){ return q; } q=q->next; } return 0; }
@AMANSAINI-qq7pm
@AMANSAINI-qq7pm 2 жыл бұрын
how can we do this using stack ?? anyone know ??
@wonderfulquotes6484
@wonderfulquotes6484 3 жыл бұрын
please don't make any video private..
@harshdasila6680
@harshdasila6680 Жыл бұрын
understoooooooooooooooooooooooooooooooood
@aaaa-pr2dd
@aaaa-pr2dd 3 жыл бұрын
Great explanation, but please upload more videos a day Please
@amanaswal11
@amanaswal11 3 жыл бұрын
Thankyou so much for the Optimal 2 approach 😻🚀
@atibhu
@atibhu 3 жыл бұрын
grt explaination, thanks for this...
@spyrowolf2211
@spyrowolf2211 2 жыл бұрын
Hi Striver, do you have a discord group?
@harshitgupta3393
@harshitgupta3393 3 жыл бұрын
Can we use Link List Cycle Detection in interviews by creating a chain of 1st Linked List and check if cycle is formed or not and where is this cycle forming and break cycle before returning the answer? P.S Sorry for my name this is not my main ID that's why.
@harshitgupta3393
@harshitgupta3393 3 жыл бұрын
I have also coded it and it's working. Will it be also a good method to tell the interviewer?
@error-my9ut
@error-my9ut 8 ай бұрын
cases with cycle will fail with the help of this approach, idk why ppl are overlooking it this much
@amirthak4743
@amirthak4743 7 ай бұрын
But in the description, it is mentioned that there won't be any cycles nah? Let me know if you think otherwise😊
Detect a Cycle in Linked List | Amazon | Samsung | Microsoft
11:36
take U forward
Рет қаралды 128 М.
Survive 100 Days In Nuclear Bunker, Win $500,000
32:21
MrBeast
Рет қаралды 165 МЛН
This Dumbbell Is Impossible To Lift!
01:00
Stokes Twins
Рет қаралды 30 МЛН
КАКУЮ ДВЕРЬ ВЫБРАТЬ? 😂 #Shorts
00:45
НУБАСТЕР
Рет қаралды 3,4 МЛН
هذه الحلوى قد تقتلني 😱🍬
00:22
Cool Tool SHORTS Arabic
Рет қаралды 31 МЛН
Merge Two Sorted Lists | Microsoft | Yahoo | Amazon
20:47
take U forward
Рет қаралды 196 М.
Will the TECH HIRING MARKET recover ever ? JOBS reducing!!
12:20
Trapping Rainwater | Brute | Better | Optimal | with INTUITION
23:23
take U forward
Рет қаралды 269 М.
I cleared NEET PG in first attempt by disappearing for 10 months
12:27
Abhijeet Archives
Рет қаралды 80 М.
Intersection of Two Linked Lists - Leetcode 160 - Python
8:13
Recursion Special: Predict Winner of Circular Game || Algorithms for Placement
22:59
Reverse Nodes in k-Group | Among the toughest problems of LinkedList
20:05
L14. Detect a loop or cycle in LinkedList | With proof and Intuition
20:26
L9. Combination Sum II | Leetcode | Recursion | Java | C++
32:37
take U forward
Рет қаралды 425 М.
Survive 100 Days In Nuclear Bunker, Win $500,000
32:21
MrBeast
Рет қаралды 165 МЛН