Reverse Linked List II | Clean Approach | Dry Run | MICROSOFT | Leetcode - 92 | codestorywithMIK

  Рет қаралды 9,638

codestorywithMIK

codestorywithMIK

Күн бұрын

Пікірлер: 62
@tsukuruuu
@tsukuruuu Жыл бұрын
even though i solved it on my own today, i wasnt satisfied with my solution. So came here to watch as usual and learnt so many new things! Thank you sir!
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you so much for watching😇🙏
@Abhay14
@Abhay14 Жыл бұрын
Bhai thanks a lot Tum normal Hindi language me itna achha samjha dette ho baki log sirf eng jhaadte rhte h simple si cheez ko complex bna dette h
@codestorywithMIK
@codestorywithMIK Жыл бұрын
It means a lot to me Abhay. Thank you for watching ❤️❤️❤️
@GeniusOG
@GeniusOG Жыл бұрын
Solved By My OWN wand learnt a new way from your video explanation thank you bhaiya 😀
@Aryan_Singh19
@Aryan_Singh19 Жыл бұрын
Thanks to these last few link list questions and you explanation I was able to solve today's daily on my own.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
So happy to hear that ❤️🙏😇
@thekindspill
@thekindspill Жыл бұрын
I knew your approach will be the cleanest. Loved the way you build from diagram to code. Thanks a lot
@ugcwithaddi
@ugcwithaddi Жыл бұрын
You are just Fantastic and such a powerful teacher 🔥🔥🔥
@dhairyachauhan6622
@dhairyachauhan6622 Жыл бұрын
solved on my own but i didn't use dummy node. I knew how they work but didn't know when to use them hence my code is complicated.Thanks you bhai for explaining it class Solution { public: ListNode* reverseBetween(ListNode* head, int left, int right) { int count = right - left + 1; if(count == 1){ return head; } left = left-1; ListNode*curr = head; ListNode *temp1 = head; while(curr && left){ temp1 = curr; curr = curr->next; left--; } ListNode *temp2 = curr; ListNode * prev = NULL; ListNode *next = NULL; while(curr && count){ next = curr->next; curr->next = prev; prev = curr; curr = next; count--; } if(temp1 == temp2){ temp2->next = curr; return prev; } else{ temp2->next = curr; temp1->next = prev; } return head; } };
@codestorywithMIK
@codestorywithMIK Жыл бұрын
I am so glad you solved it on your own. Way to go 💪💪💪 See my pinned comment ❣
@dhairyachauhan6622
@dhairyachauhan6622 Жыл бұрын
@@codestorywithMIK hats off for writing so many approaches
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you 🙏❤️😇
@saurabhtiwari9614
@saurabhtiwari9614 Жыл бұрын
One word only for u -Legend❤❤❤
@codestorywithMIK
@codestorywithMIK Жыл бұрын
It means a lot ❤️❤️❤️😇🙏
@AlishaKhan-ww3io
@AlishaKhan-ww3io Жыл бұрын
Big Big Fan of your teaching style Sir
@wearevacationuncoverers
@wearevacationuncoverers Жыл бұрын
Hats off to the unique way you make things simple. Loved the diagram approach for Linked List problems. It helped me in other problems as well.
@aInvincibleProgramer789
@aInvincibleProgramer789 Жыл бұрын
❤ thanxx sir ,,me kbhi bhi question me stuck hota hu toh yhi aata hu
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Means a lot 😇🙏❤️
@susmitapatil4847
@susmitapatil4847 10 ай бұрын
Really good explanation. Best video on this problem. Keep doing such a good work
@MounikaEMB
@MounikaEMB Жыл бұрын
You thought us in a very simpler manner....Thank you so much 😊👏🙏
@codestorywithMIK
@codestorywithMIK Жыл бұрын
My pleasure 😊
@Vipulghadi
@Vipulghadi Жыл бұрын
ListNode*reverse(ListNode*head,ListNode*after) { ListNode* pre=NULL; ListNode*cur=head; while(cur!=after){ ListNode*nextele=cur->next; cur->next=pre; pre=cur; cur=nextele; } return pre; } ListNode* reverseBetween(ListNode* head, int left, int right) { ListNode*before,*after,*temp; ListNode*dummy=new ListNode(0); left--; dummy->next=head; temp=dummy; for(int i=0;inext; } after=temp->next; before->next=reverse(before->next,after); temp=before->next; while(temp->next)temp=temp->next; temp->next=after; return dummy->next; }
@souravjoshi2293
@souravjoshi2293 Жыл бұрын
loved the way of explanation bro. amazed ❣
@manimanohar_001
@manimanohar_001 Жыл бұрын
Bro do you remember me?( the REMAINDER guy). I have been constantly asking you this question since February. But by god's grace LC pulled this on daily challenge so that you could solve & present to me.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
The only person that came to my mind when I saw this qn in the morning was You 😇 I feel bad it got delayed till this day, apologies for that brother. Hope you understand. But I was so happy to see this qn finally. And I really hope this video helps you 🙏🙏❤️❤️
@manimanohar_001
@manimanohar_001 Жыл бұрын
@@codestorywithMIK it's been 3-4 months since I stopped asking you due to some financial crisis & many other problems. Amid this I totally forgot but today LC reminded me😔
@manimanohar_001
@manimanohar_001 Жыл бұрын
BTW THANKS BHAIYA👍
@codestorywithMIK
@codestorywithMIK Жыл бұрын
I hope everything is well by your side. Thank you for putting your trust in my channel 🙏❤️
@Tejaswi-xd4re
@Tejaswi-xd4re Жыл бұрын
Sir pls make a dsa batch so that beginners will get full guidance from u and can study from basic to advanced dsa with stories
@codestorywithMIK
@codestorywithMIK Жыл бұрын
I will surely plan this but I am very occupied for next 2 months as I am traveling out of India and will have a busy schedule. But definitely i will soon plan that.
@AlishaKhan-ww3io
@AlishaKhan-ww3io Жыл бұрын
@@codestorywithMIK where are you going mid bhaiya ?
@sarthakyadav9950
@sarthakyadav9950 Жыл бұрын
My approach was to detach the part of the linked list from left to right pass it to a new function to reverse it and then attach it back to the original list. Will this work in an interview? Considering that Time and Space complexity were same as your solution.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Definitely it will work. There are different ways to solve this. See my Pinned Comment ❤️❤️
@gui-codes
@gui-codes 7 ай бұрын
clean. loved it.
@namanpadiyar09
@namanpadiyar09 4 ай бұрын
class Solution { public: ListNode* rev(ListNode* head) { ListNode *prev=NULL , *curr= head , *Next=head; while(curr!=NULL){ Next= curr->next; curr->next= prev; prev=curr; curr=Next; } return prev; } ListNode* reverseBetween(ListNode* head, int l, int r) { if(left==right) return head; ListNode* ans = head; ListNode* temp = head; int n=1; ListNode* a=NULL; ListNode* b=NULL; ListNode* c=NULL; ListNode* d=NULL; while(temp!=NULL){ if(n==l-1) a=temp; if(n==l) b=temp; if(n==r) c=temp; if(n==r+1) d=temp; temp=temp->next; n++; } if(a) a->next=NULL; c->next=NULL; c=rev(b); if(a)a->next=c; b->next=d; if(a)return ans; else return c; } };
@manaskhare412
@manaskhare412 Жыл бұрын
Hi. Thank you for your explanation. I think we can solve this problem by using the reverse function of the singly linklist, just need to paas the left associated node and make the next of right associated node NULL. After reversing it, connect it with the required nodes. What's your take on this?
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Yep definitely. See my pinned comment 😇🙏❤️
@dayashankarlakhotia4943
@dayashankarlakhotia4943 Жыл бұрын
using stack. class solution { public List Node reverse Between ( List Node head,int left,int right){ if(head ==null ||left ==right) return head; Like Node node =head; int count =1; stack st= new stack (); while (count =right){ if(left =count){ node.val=st.pop(); } count ++; node=node.next; } return head; } }; Tc=0(n) sc=0(n) 2nd approach. tc=0(n) sc=0(1). class solution{ public List Node reverse Between (List Node head,int left,int right){ if(head ==null ||left ==right) return head; List Node dummy =new List Node (0); dummy. next =head; List Node prev=dummy; for(int i=0;i
@BenJasper-u2x
@BenJasper-u2x Жыл бұрын
Hi like you have started with linkedlist right now Can you tell me which data structure you will start after this
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Hi there, Actually all data structures playlist are present in my playlist. I keep posting qns in all of them one by one. My channel has two types of playlists: 1) Popular Interview qns on a Data Structure/topic 2) Concepts and basic fundamentals of that topic. Example : I have two playlists of Graph and DP one is for qns and other is for concepts building. Please find them in my playlist section. More concepts playlist will be coming soon.
@codeandtalk6
@codeandtalk6 Жыл бұрын
❤❤
@AshutoshEE-
@AshutoshEE- Жыл бұрын
Sir one doubt problem description me niche likha h could you do it in one pass ? But apke approach me hmne do baar for loop lgaya h kya ise ek baar me hi nhi kr skte?
@codestorywithMIK
@codestorywithMIK Жыл бұрын
One pass means we can’t traverse the Linked list more than once. If you notice my approach does not traverse the entire linked list more than once.
@umeshbisht1054
@umeshbisht1054 Жыл бұрын
Thanku bhaiya ❤
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Most welcome ❤️🙏😇
@jagadeeshp1163
@jagadeeshp1163 Жыл бұрын
first like❤
@kondkartauqeer5503
@kondkartauqeer5503 Жыл бұрын
15:07 mai prev -> next -> next = temp (which is prev -> next which is b), toh prev -> next -> next should be d naa???? Since prev -> next c hogaya hai toh uska next d hoga naa??? C kaise hua??? I am really confused
@sanskargupta1087
@sanskargupta1087 8 ай бұрын
sir i am a newbie so can u plz tell what if we change values of nodes instead of structure of linked list in this question? as the answer will be same
@codestorywithMIK
@codestorywithMIK 8 ай бұрын
If you change the values of the nodes that will be correct too. It will seem as reversed. But the Leetcode compiler might have test cases in the background to check that and might not accept the solution. Generally in interviews , the problem is asked to reverse the Pointer (change structure)
@sanskargupta1087
@sanskargupta1087 8 ай бұрын
Understand ! and Thank u so much sir for ur fast reply❤@@codestorywithMIK
@jagadeeshp1163
@jagadeeshp1163 Жыл бұрын
dummy=ListNode(-1) dummy.next=head i=0 thead=dummy l=None r=None while(thead): if i==left-1: first_cut=thead if i==left: l=thead if i==right: r=thead if r.next: last_cut=r.next if r.next==None: last_cut=None r.next=None thead=thead.next i+=1 first_cut.next=None #reverse from l to r prev=None curr=l thead=l while(thead): thead=thead.next curr.next=prev prev=curr curr=thead first_cut.next=prev l.next=last_cut return dummy.next using many pointers but achieved the answer will this be accepted in the interview ?? Should linked list problems be solved with as minimum pointers as possible ?
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Definitely 👍🏻 Buy always try to keep the code as simple as possible.
@taneyasoni
@taneyasoni Жыл бұрын
7/30
@saurabhKumar-hj6yp
@saurabhKumar-hj6yp Жыл бұрын
First comment 😂
@jagadeeshp1163
@jagadeeshp1163 Жыл бұрын
no its mine lol :)
@AdityaGupta-zd5sq
@AdityaGupta-zd5sq Жыл бұрын
approch is quit difficult
@NITianMonika
@NITianMonika Жыл бұрын
Aapki video search engine me nhi aati sir, Aap only one headline rakhna sir next time se sayad search engine me aane lage (Problem ke name se). For only experiments..........mujhe to proper channelpe aa kar khojni pdti hai. etne m m bhatk jati hu ki kya karne aayi thi yt pe or phir idher udher ka content consume karne ke baad realise hota hai kyo time waste kiya jo karne aayi vo khoj
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Hey, thank you for this feedback. I think it happens sometimes when someone has not subscribed to the channel. Can you trying Subscribing and also clicking the Bell icon. I think that will help. Kindly let me know if that helped. Else I will try to optimise my headline.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Hi there, Today’s POTD - kzbin.info/www/bejne/j6rYqIetjd-Grrssi=3V52dtkNtegWjhV-
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Hi guys, Please note that there can be many ways to solve this problem. I chose to go with this solution for two reasons : 1. So that you can understand the importance of taking dummy node in future problems. 2. How first diagrammatically solving helps to write the code. Multiple approaches can be found in my repo here - github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Linked%20List/Reverse%20Linked%20List%20II.cpp iPad PDF Notes - github.com/MAZHARMIK/Interview_DS_Algo/blob/master/iPad%20PDF%20Notes/Leetcode-92-Reverse%20Linked%20List%20II.pdf Thank you and love you all ❣
@MounikaEMB
@MounikaEMB Жыл бұрын
for(int i=1;inext; I didn't understand this step here 20:12 Can you please explain
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 6 МЛН
When u fight over the armrest
00:41
Adam W
Рет қаралды 31 МЛН
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
Noodles Eating Challenge, So Magical! So Much Fun#Funnyfamily #Partygames #Funny
00:33
92. Reverse Linked List II
15:30
Tech Adora by Nivedita
Рет қаралды 3 М.
Reverse Linked List II - Leetcode 92 - Python
16:03
NeetCode
Рет қаралды 85 М.
Master LeetCode 92: Reverse Linked List II | Step-by-Step Guide & Tips
13:47
Engineering Digest
Рет қаралды 1,8 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 147 М.
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 6 МЛН