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
@sagardas45694 жыл бұрын
Your voice has changed i think...
@gautamsuthar41433 жыл бұрын
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
Thanks for this explanation! Please don't stop this ever, best thing on Internet.
@takeUforward4 жыл бұрын
Glad :)
@anupamayadav70383 жыл бұрын
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-qf1iz2 жыл бұрын
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 Жыл бұрын
Sadly it may not be the case with the interviewer.
@RV-qf1iz Жыл бұрын
@@anurondas3853 why we cannot use hashmap in an interview ?
@pranav288 Жыл бұрын
@@RV-qf1iz extra space is not good
@jatinukey4062 Жыл бұрын
@@RV-qf1izthey will ask to optimize the space complexity 😅
@_-69123 жыл бұрын
I'm happy actually, first best solution was something even I came up the first time when I was doing this question.
@omhari82973 жыл бұрын
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; }
@JyotiSharma-wb1vy Жыл бұрын
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!
@abhay9994 Жыл бұрын
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!❣✨✨
@paragsaini27954 жыл бұрын
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
@yatinarora12523 жыл бұрын
In this question there is mentioned there is no cycle in linked list
@justarandomguy61062 жыл бұрын
Good observation
@virusnetic2 жыл бұрын
@@yatinarora1252 you can just make a cycle by updating tail_of_first_ll.next = head_of_first_ll and revert it back.
@himanshumaurya4282 жыл бұрын
@@virusnetic you are not allowed to change the structure of LL.
@sourabhkumar5815 Жыл бұрын
That's a very creative approach. but it won't cover the case when there is no merge point.
@dipakraut60584 жыл бұрын
The second approach was just Amazing.
@jaskiratsinghosahan46384 жыл бұрын
Best DSA series on whole KZbin🔥🔥
@joydeb82024 жыл бұрын
Love your Videos............ Following this series since 2weeks .......... You are inspiration dude..... ; ) Get well sooooooooon...waiting for your comeback... take rest
@lokeshvikram61924 жыл бұрын
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.
@pranav2882 жыл бұрын
hey did only doing sde sheet work for you ? how was your interview experience ?
@Paul_atredis2 жыл бұрын
@@pranav288 well he didn't replied but what about you? did the sheet helped you?
@pranav288 Жыл бұрын
@@Paul_atredis I cracked the very first interview I appeared for. Still looking for more opportunities, will keep you posted.
@abhivarma1756 Жыл бұрын
@@pranav288 update please
@viveksingh_01 Жыл бұрын
@@pranav288 any updates?
@mahithareddymaram45163 жыл бұрын
The explanation is super easy to understand. Thanks !! keep up the good work
@positivity53584 жыл бұрын
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...
@takeUforward4 жыл бұрын
But am not a bengali XD
@positivity53584 жыл бұрын
@@takeUforward I know that well but still that could be because you may have lived in Bengal that why....🙂🙂
@AditiPawar-u5q Жыл бұрын
wow!!!!!! Amazing solutions. I hope one day I will be able to solve like this.
@ranasauravsingh2 жыл бұрын
UNDERSTOOD... !!! Thanks, striver for the video... :)
@techykush71924 жыл бұрын
wow amazing explanation love u bhaiya keep it up thanks a lot 😍😍
@toshanverma10843 жыл бұрын
second approach is just wow. Thankyou.
@bhaveshkumar68423 жыл бұрын
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 Жыл бұрын
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
@nishantingle14383 жыл бұрын
Best thing is the explanation rather than the code. You're awesome.
@rishikeshpawar32302 жыл бұрын
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.
@ayushshukla15974 жыл бұрын
Even the interviewer would not know about the 2nd Optimal Solution. Amazing work.
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-mc7qe3 жыл бұрын
@@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
@joseph20732 жыл бұрын
legend dude
@reassume48263 жыл бұрын
Mind-blowing moment @13:17
@ДенисМ-д7ъ Жыл бұрын
The best explanation. Thank you
@surajsarmahpathak926 Жыл бұрын
Very imp concept. Thanks Striver !
@oqant04243 жыл бұрын
after your hint i coded it myself..your logic explanation is very gd
@jitendrapal42166 ай бұрын
Your explanation is great ❤
@aditinagda66093 жыл бұрын
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 Жыл бұрын
Yeah this approach will work also
@kaushikramabhotla46353 жыл бұрын
the second optimal approach is 🔥🔥 !!! aag laga di bhai :)
@jatinkumar4410 Жыл бұрын
Amazing approach, amazing explanation
@udayjordan42622 жыл бұрын
basically you can also use hashmap if interviewer doesnt ask you space optimize it more .i mean constant space.
@pranshumehta32282 жыл бұрын
Time complexity of 2nd optimal solution would be O(m+n) in worst case Isn't it?
@hariprasadsa82633 жыл бұрын
In Optimal 2 Answer I was astonished by the way you have shown us to solve...Keep going man!
@alokkumar-ki7wp2 жыл бұрын
Love you Striver!! What a code that was of 2nd optimal solution.
@hackpiece30944 жыл бұрын
Thank you so much ❤️ Keep up the good work brother😁
@kaichang81863 ай бұрын
understood, thanks for the detail explanation
@oqant04243 жыл бұрын
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
@ShaikSharma2 ай бұрын
i have my accolite interview today hoping the best
@vidhi_bhatt2 жыл бұрын
Beautifully explained!!
@adityan53022 жыл бұрын
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
@jaswantrohila37764 жыл бұрын
What a solution 🔥🔥 didn't thought of this....thanks
@factfactorial6322 жыл бұрын
Great Explanation Bhaiya I think TC of last solution should be O(m+n) correct me if I am wrong
@manistrikes2 жыл бұрын
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
@prestoX Жыл бұрын
Beautiful explanation.
@calmyourmind56172 жыл бұрын
" Obviously the interviewer will not be happy and he will ask you to optimize the approach" - has a separate fanbase.
@venkatsaireddy141211 ай бұрын
I like the technique♥
@krishnavamsichinnapareddy Жыл бұрын
Superb explanation ❤
@yogeshvaishnav64643 жыл бұрын
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.
@yogeshvaishnav64643 жыл бұрын
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 !😂
@takeUforward3 жыл бұрын
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.
@anchitmittal65463 жыл бұрын
Very Well Explained. Thanks Mate 👍
@gautamsuthar41433 жыл бұрын
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.
@chowmein13973 жыл бұрын
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
@gautamsuthar41433 жыл бұрын
@@chowmein1397 thanks. I appreciate it.
@shreyasingh12584 жыл бұрын
The way you explain really helps alott!!!thanks bhaiya🙌
@takeUforward4 жыл бұрын
Glad to hear that
@_hulk7482 жыл бұрын
understood sir ji🙏🙏
@Ashwani_sharma Жыл бұрын
Last approach will not work when no intersection, stuck in while loop
@starboy415 Жыл бұрын
if(a==NULL && b==NULL) return -1; add this statement at the last in the while loop and it should work
@paragroy53594 жыл бұрын
Nice explanation sir......thanks for the playlist extremely helpful...
@way2prosperity Жыл бұрын
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?
@heysitam2 жыл бұрын
Thankyou vaiya for such an awesome explanation
@shivyanshgarg2 жыл бұрын
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?
@dhirenparekh26462 жыл бұрын
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.
@cricwhiz1512 жыл бұрын
nice explaination thank you
@ytg66633 жыл бұрын
Coming to last solution, wont it stuck in loop if no intersection found ???
@tannukumari51444 жыл бұрын
The 2nd optimal approach is 🔥, Get well soon bhaiya..waiting for your next message on telegram just after posting new video :)
@naro.tam_3 жыл бұрын
I was able to code 1st optimal by myself but 2nd one was jusssss great
@nileshsinha78694 жыл бұрын
I just solved this question last night. Amazing explanation
@takeUforward4 жыл бұрын
Glad it helped!
@anushak14462 жыл бұрын
understood thank you
@yash3009516 күн бұрын
understood!
@AmarjeetKumar-to9ub Жыл бұрын
Thank You :)
@little-by-little-one-trave17703 жыл бұрын
Great explanation. But will the last concise optimal solution run if they do not have intersection ?
@jayuchawla18922 жыл бұрын
no 😫
@ayanagrawal4 жыл бұрын
Can anyone please tell how is the case of no intersection handled in the last approach...
@samstar97774 жыл бұрын
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
@atibhu3 жыл бұрын
grt explaination, thanks for this...
@rtm48292 жыл бұрын
In the C++ code if there is no intersection point in LL how will a== b (To stops while loop)??
@khageshbansal24002 жыл бұрын
Wouldn't your algo return wrong answer of 1 at 16:11 because head a and head b have same values.
@niyom88662 жыл бұрын
ANSWER COMES RIGHT., BUT I HAVE SAME DOUBHT
@saurabhahuja67073 жыл бұрын
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)
@democratcobra3 жыл бұрын
Thanks for uploading vai....u r my motivation.
@amanaswal114 жыл бұрын
Thankyou so much for the Optimal 2 approach 😻🚀
@subhajeetchakraborty17912 жыл бұрын
wow 2nd best approach was similar to hare and tortoise method
@jeevanreddy9895 Жыл бұрын
Amazing man 🙏🙏🙏🙏🙏
@programmertik20463 жыл бұрын
first i like your videp then i watch it !!
@deependu__2 жыл бұрын
Awesome. Thanks.
@AB-tp9eg3 жыл бұрын
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
@SANCHITJAIN_3 жыл бұрын
great explanation...loved it :)
@madhunitesh15674 жыл бұрын
Really the 2nd optimal solution is just 🔥🔥🔥.
@aaryansingh37832 жыл бұрын
Is the dummy node as mentioned by bhaiya same as pointer to a Node (head of linked list) like Node * temp = head
@soummodipsaha53633 жыл бұрын
How to find the length of 2 lists simultaneously in Optimal 1 ??
@pratikvyas33843 жыл бұрын
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?
@jobanpreetsingh23703 жыл бұрын
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. 😊😊
@abdurrahaman3884 жыл бұрын
Could we able to solve this by reversing both link list and then traverse from back ?
@abhishekjha56514 жыл бұрын
It is mentioned in the question that, you cannot change the original structure of the linked list.
@priyanshunandan96483 жыл бұрын
@@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.
@rounakpattanayak68162 жыл бұрын
2nd optimal soln is faulty I guess ...if there is no insertion point I think 2nd soln will not work
@manistrikes2 жыл бұрын
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
@savalalingeshreddy67504 жыл бұрын
Thanks for the video bro good explanation Keep doing
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
@takeUforward4 жыл бұрын
It will never meet because the test case is wrong. It should have been 1,2,8,2,2 1,8,2,2
@heyrmi3 жыл бұрын
Bhaiya I am late. But I am glad I here.
@AinasDiaries3 жыл бұрын
the optimal solution solution 1 is printing the the output in gfg....whats the issue??
@priyanshunandan96483 жыл бұрын
May be you've made a mistake in your logic 😌
@debdhritiroy68683 жыл бұрын
beautifully explained
@nknidhi3214 жыл бұрын
Brilliant. Thank you
@MidoValo4 жыл бұрын
like like your so smart thank you so much
@ketankhandelwal86263 жыл бұрын
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? ..