Lecture 46: Linked List Questions: Reverse LL in "K group" && Check LL is Circular or not

  Рет қаралды 307,869

CodeHelp - by Babbar

CodeHelp - by Babbar

Күн бұрын

Пікірлер: 561
@CodeHelp
@CodeHelp 2 жыл бұрын
Do Visit Relevel: relvl.co/444e
@comment6130
@comment6130 2 жыл бұрын
First like
@ancymaria3907
@ancymaria3907 2 жыл бұрын
Hi love..pls add subtitles for ur video.. Last three DSA course videos doesn't have subtitles.. It wud b really helpful for people like me who doesn't know hindi
@mohitraj1995
@mohitraj1995 2 жыл бұрын
I m in lecture 5🙂 I want complete fast to cover and see daily wise latest update
@ashutosh61290
@ashutosh61290 2 жыл бұрын
@Devesh bhai wo bhi insaan hai.. thoda unke bare me bhi socho. itna speed toh video daal rhe hai.. ab kya ek din me 5 video daal de tumhare liye.
@nehasharma6171
@nehasharma6171 Жыл бұрын
circularlly linked ka ques code studio pe is logic se karne se saare test cases ren nhi horhe h . 😔
@anishtripathi3800
@anishtripathi3800 4 ай бұрын
Watching this in July 2024.. still the best lecture series, and I will complete it all. To the people watching it, I request you to not watch it from the middle if you're a beginner. I had consistently watched it from lecture 1, and trust me, this will help you pass with flying colors.
@feagy
@feagy 9 ай бұрын
FOR EVERY ONE DOING IT NOW TEST CASE HAS BEEN CHANGED ...current code will work after doing little bit change HERE IS THE CORRECT CODE int getlength(Node*head,int k){ int c=0; while(head!=NULL){ c++; head=head->next; } return c; } Node* kReverse(Node* head, int k) { // Write your code here. //base case if(head==NULL){ return NULL; } Node*prev=NULL; Node*curent=head; Node*forward=NULL; int c=0; while(curent!=NULL && cnext; curent->next=prev; prev=curent; curent=forward; c++; } // if(forward!=NULL ){ // head->next=kreverse(forwars,k); if(getlength(forward,k)>=k){ head->next = kReverse(forward, k); } else{ head->next=forward; } } return prev; }
@mannan7126
@mannan7126 7 ай бұрын
thanks man :))
@manavgupta1558
@manavgupta1558 5 ай бұрын
Only adding getlength on base condition can give correct answer i.e. int getlength(ListNode* head){ int n=0; ListNode* temp = head; while (temp!=NULL) { temp=temp->next; n++; } return n; } ListNode* reverseKGroup(ListNode* head, int k) { if(head==NULL || getlength(head)next=prev; prev=curr; curr=temp; cnt++; } if(temp!=NULL) head-> next= reverseKGroup(curr,k); return prev; } hope so its easier to understand.
@aviii24x7
@aviii24x7 4 ай бұрын
After 2 hours of trying, you helped htanks!!!
@khushigupta1783
@khushigupta1783 4 ай бұрын
what change has been made to the question now?can anyone tell..is it that the nodes out of the k value left at end will be left as it is?
@aviii24x7
@aviii24x7 4 ай бұрын
@@khushigupta1783 The node that left (less than k) should not be affected, changes to be applied only if next k nodes are availbale
@viral_plays1081
@viral_plays1081 2 жыл бұрын
Dheerr sarreee bde se bdee youtube channels, but apki energy and way of teaching.....MIND BLOWING!!!!
@ninjahattori4101
@ninjahattori4101 2 жыл бұрын
NIce Explanation Keep the josh high, we are with you following the course from the very start video
@sauravdhar1696
@sauravdhar1696 2 жыл бұрын
Completing the first phase in depth but still watching the videos that you upload daily taaki aapka motivation na down ho bhaiyya ....awesome work (march tak khatam kar denge sab kuch)
@snipper6683
@snipper6683 2 жыл бұрын
konse year may ho bhai!
@AS-gf3ci
@AS-gf3ci Жыл бұрын
For Leetcode : (Only slight changes to this video's solution) int getLength(ListNode* head) { int length = 0; ListNode* temp =head; while(temp != NULL) { length++; temp = temp -> next; } return length; } ListNode* reverseK(ListNode* &head, int k, int length) { //Base case if(head == NULL || head -> next == NULL || k == 1 || length < k) return head; //Step 1 : Reverse first k nodes ListNode* nxt = NULL; ListNode* curr = head; ListNode* prev = NULL; int count = 1; while(curr != NULL && count next; curr -> next = prev; prev = curr; curr = nxt; count++; } //Step 2 : Reverse next k nodes using recursion if(nxt != NULL) { head -> next = reverseK(nxt, k, (length - k)); } //Step 3 : Return head of the reversed linked list head = prev; return head; } ListNode* reverseKGroup(ListNode* head, int k) { int len = getLength(head); return reverseK(head, k, len); }
@shantanumore5396
@shantanumore5396 Жыл бұрын
thanks much needed!
@dreamy4174
@dreamy4174 Жыл бұрын
Getting difficulty in recusion problems .Any suggestion 🥺
@vakeelsaab5485
@vakeelsaab5485 Жыл бұрын
@@dreamy4174 spend more time on recursion dry run
@meetmakwana3427
@meetmakwana3427 9 ай бұрын
Thanks a ton MVP
@motives748
@motives748 7 ай бұрын
bro the length function is much needed without it the solution gives wrong ans thanks
@RedSpade01
@RedSpade01 Жыл бұрын
APPROACH For anyone stucking in cases in codestudio or leetcode, the problem is this code reverses even if k is greater than remaining numbers, so you gotta check the size in every recursion(basically in one case your working), then mark k>size{return head}, this will do the job. edit: I will post my edited code but try once yourselves its easy
@tejasshinde7236
@tejasshinde7236 Жыл бұрын
Thanks
@rohitss671
@rohitss671 Жыл бұрын
yes i also found that after reading the question i understand what to do ---
@Sukoon_3000
@Sukoon_3000 Жыл бұрын
thanks but was stuck for 1 hr
@PrajjvalMishra-g5f
@PrajjvalMishra-g5f Жыл бұрын
thanks
@RedSpade01
@RedSpade01 Жыл бұрын
@@Sukoon_3000 No prob buddy, I was stuck for an hour here too😅
@deeppatel0586
@deeppatel0586 2 жыл бұрын
Babbar sir, love your content. told many friends about this course. Infinite gratitude from my side :)))))))))
@RahulKumar-ye2iy
@RahulKumar-ye2iy 2 жыл бұрын
This code will reverse every elements in group even if the no. of elements in one group is less than k. So, here's the updated code which will take care this condition. class Solution { public: ListNode* _reverseKGroup(ListNode* head, int size, int k){ if(head==nullptr || sizenext=prev; prev=cur; cur=next; count++; } head->next=_reverseKGroup(next, size-k, k); return prev; } ListNode* reverseKGroup(ListNode* head, int k) { int size=0; ListNode* temp=head, *root; while(temp!=nullptr){ temp=temp->next; size++; } return _reverseKGroup(head, size, k); } };
@shubhamgarad657
@shubhamgarad657 Жыл бұрын
Thanks guru
@codehunter-gu1qi
@codehunter-gu1qi 5 ай бұрын
not working input : 6 5 4 3 7 9 2 4 output : 7 3 4 5 desired output : 7 3 4 5 9 2
@anushravgarg5042
@anushravgarg5042 2 жыл бұрын
Bhaiya excellent work, after 5 months i am seeing these videos but this is one of the really nice explained content i have got ,even after seeing 1-2 paid courses i can say this clearly that this is best and keep up good work babbar bhai
@daiict2282
@daiict2282 2 жыл бұрын
Easiest solution of k reverse hats off bhaiya kya smjhaya ha apki wahaj sa kitna bacho ka future secure ho raha ha
@kaushikjain9697
@kaushikjain9697 2 жыл бұрын
Babbar sir, love your content. told many friends about this course. Infinite gratitude from my side
@sakshamgarg5638
@sakshamgarg5638 2 жыл бұрын
Keep the josh high, we are with you following the course from the very start video
@harshjain7945
@harshjain7945 2 жыл бұрын
Your way of teaching is unmatchable sir! Big fan of you sir!
@rahulstudies1178
@rahulstudies1178 2 жыл бұрын
doubly linked list reverse Node* reverseDLL(Node * head) { Node* curr=head; Node* pre=NULL; Node* forward=NULL; while(curr!=NULL){ forward=curr->next; curr->prev=curr->next; curr->next=pre; pre=curr; curr=forward; } return pre; }
@sushil4-yearb.tech.electri218
@sushil4-yearb.tech.electri218 Жыл бұрын
If anyone doing now is getting stucked in some test cases, then the updated code is here : Node* kReverse(Node* head, int k) { int size = 0; Node* temp = head; while(temp!=NULL){ temp = temp -> next; size++; } if(size < k)return head; // just add this new part in code so that, when number of nodes is not a multiple of k, the left over ones are not to be reversed. if(head == NULL){ return NULL; } // step 1: reverse first k nodes Node* prev = NULL; Node* curr = head; Node* next = NULL; int count = 0; while(curr != NULL && count < k){ next = curr -> next; curr -> next = prev; prev = curr; curr = next; count ++; } // step 2: recursion if(next != NULL){ head -> next = kReverse(next, k); } // step 3: return head return prev; }
@Anshucc
@Anshucc Жыл бұрын
nice edge case pass ho gye badhiya code logic
@aditighate7191
@aditighate7191 Жыл бұрын
@@Anshucc Thank you!
@ankitgaur7428
@ankitgaur7428 Жыл бұрын
Thanks bro
@simplesolutions2621
@simplesolutions2621 2 жыл бұрын
Excellent going, bhaiya!! Keep the Josh High!!! Hum SAATH HAI!!❤ Thode din ka gap ho sakta hai..to cover up and do more questions from previous videos!! 👍
@samaysarah7417
@samaysarah7417 2 жыл бұрын
Dhanyawaad bhaiya iss course ke liye....
@investwithus9271
@investwithus9271 2 жыл бұрын
Daily video chahiye... We support you... Completed video
@siddharthsingh5510
@siddharthsingh5510 Жыл бұрын
In question 1: reverse linked list in k groups, this is O(1) space complexity and O(n) time complexity code which i written myself: Passed all the testcases. Node* kReverse(Node* head, int k) { Node* curr = head; Node* prev = NULL; Node* forward = NULL; int j=0; Node* ultimatehead = NULL; Node* mogambo = NULL; while(curr!=NULL){ Node* tempo = curr; int i=1; while(inext; prev = curr; curr = forward; i++; } else{ forward = curr->next; curr->next = prev; prev = curr; curr = forward; i++; } } if(j==0){ ultimatehead = prev; tempo->next = curr; prev = tempo; mogambo = tempo; j++; } else{ mogambo->next = prev; tempo->next = curr; prev = tempo; mogambo = tempo; j++; } } return ultimatehead; }
@arncs5587
@arncs5587 2 жыл бұрын
Class ase chalraha he ki may be meri break failure ho jayega 😂😂😂👍👍👍 thanks bhai continue ......❤️❤️ Lot of love from Amosh ....❤️❤️❤️
@srivathsav4587
@srivathsav4587 Жыл бұрын
For leetcode you have to stop if there are less than k nodes: Just add this after your, if(head==NULL) condition: ListNode *d=head; for(int i=0;inext; }
@maidaiftikhar6901
@maidaiftikhar6901 Жыл бұрын
could you please explain the logic for this?
@AkshatChaudhary-fe3vv
@AkshatChaudhary-fe3vv Жыл бұрын
Bro check LL is giving TLE in coding studio 😢
@naitik554
@naitik554 2 жыл бұрын
Bhaiya hum dekhte hain aap banate jaaye.... Josh is always high because of you and your consistency.... Thank you bhaiyaa....😊😊
@Nishankjain-cw4jh
@Nishankjain-cw4jh 4 ай бұрын
question 1 contains one more base condition that if the length is less than k than return rest of the LL as it is here is the enhanced code /** * Definition for singly-linked list. * class Node { * public: * int data; * Node *next; * Node() : data(0), next(nullptr) {} * Node(int x) : data(x), next(nullptr) {} * Node(int x, Node *next) : data(x), next(next) {} * }; */ Node *kReverse(Node *head, int k) { if (head == NULL) return head; int len = 0; Node *check = head; while (check != NULL) { len++; check = check->next; } if (len < k) { return head; } if (head == NULL) { return NULL; } // step1: reverse first k nodes Node *prev = NULL; Node *curr = head; Node *next = NULL; int count = 0; while (curr != NULL && count < k) { next = curr->next; curr->next = prev; prev = curr; curr = next; count++; } // step2: Recursion dekhlega aage ka if (next != NULL) { head->next = kReverse(next, k); } // step3: return head of reversed list return prev; }
@GaneshBhutekar-nu1gd
@GaneshBhutekar-nu1gd 3 ай бұрын
bro tu knse year main hain
@AbhishekVerma-gg4hf
@AbhishekVerma-gg4hf 2 жыл бұрын
Bhaiya aap ka hi Sahara hain ..aap kyu apna motivation down kr rahe ho . We are with you🤝
@sambhavsharma2780
@sambhavsharma2780 2 жыл бұрын
For leetcode class Solution { public: ListNode* reverseKGroup(ListNode* head, int k) { if(head == NULL) return NULL; // reverse first k nodes ListNode* prev = NULL; ListNode* curr = head; ListNode* forward = NULL; ListNode* temp = head; int count = 0; // count remaining nodes int countNodes = 0; while(temp != NULL){ countNodes++; temp = temp->next; } if(countNodes >= k){ while(curr != NULL && count < k){ forward = curr->next; curr->next = prev; prev = curr; curr = forward; count++; } if(forward != NULL){ head->next = reverseKGroup(forward, k); } }else{ return head; } return prev; } };
@neerajmahapatra5239
@neerajmahapatra5239 2 жыл бұрын
Can you explain why countNodes>=k working
@sambhavsharma2780
@sambhavsharma2780 2 жыл бұрын
@@neerajmahapatra5239 it works because every time when we call next reverseKGroup function. first we count remaining nodes and if remaining nodes is greater than or equal to K then we only reverse that group if it is less than K then we simply return head means no need to reverse further. Hope you understand.
@111rhishishranjan2
@111rhishishranjan2 Жыл бұрын
Post leetcode code for circular linkedlist or not
@parthibbanerjee5994
@parthibbanerjee5994 Жыл бұрын
​@@sambhavsharma2780 for i/p : 1 2 3 4 5 and k = 3......after the reversal of (1, 2, 3) when it comes to the recursion part for (4, 5), countnodes=2..... so (countnodes >= k) condition becomes false right??....then in that case how reversal of (4, 5) is happening?? can u pls explain this!!
@rakshitgupta1771
@rakshitgupta1771 Жыл бұрын
@@parthibbanerjee5994 do this little change in it.... node *reversek(node *head, int k) { if (head == NULL) { return NULL; } node *temp = head; int cntnodes = 0; node * ans = NULL; while (temp != NULL) { cntnodes++; temp = temp->next; } if (cntnodes >= k) { node *forw = NULL; node *curr = head; node *prev = NULL; int cnt = 0; while (curr != NULL && cnt < k) { forw = curr->next; curr->next = prev; prev = curr; curr = forw; cnt++; } if (forw != NULL) { head->next = reversek(forw, k); } ans = prev; } else return head; return ans; }
@sounaksaha1455
@sounaksaha1455 2 жыл бұрын
Ennnnnnnnnerrrrrrrrggggy!!!!! Bhaiya aap video laate rahiye....... hum placement leke hi manenge.
@amandwivedi976
@amandwivedi976 2 жыл бұрын
Bhaiya abhi mai lecture 20 pe hoon, Attendence marked thnq so much for awesome videos
@AbhishekVerma-gg4hf
@AbhishekVerma-gg4hf 2 жыл бұрын
Bhaiya aap lage raho hm log aap k saath hain
@SriniVas-mx1li
@SriniVas-mx1li 2 жыл бұрын
Bhai tuuu... humra pyaar hi ♥️ Attendance from Andhra Pradesh 🥳🥳🥳
@anuragpandey8165
@anuragpandey8165 2 жыл бұрын
39:54 Bhai dekh rahe hai hamesha.... Like bhi krre hai...... Roz video chahiye
@prishasureja5280
@prishasureja5280 2 жыл бұрын
woaahhh sir pls keep uploading we are watching this series regularly!!!!!
@ekengineer9868
@ekengineer9868 2 жыл бұрын
Bhaiyaa ji consistency op🔥 And don't get disappointed by less comments it is because many of us are left with previous lectures 🥲
@sabhavathyashwanth9145
@sabhavathyashwanth9145 2 жыл бұрын
Hello sir I'm a btech 1st year student of it branch. I'm done with C and wanted to switch to C++. Kya mein es playlist ko follow kar sakta hun ya should I see other playlist like whole C++ lectures as esme DSA bhi included hai na. Please suggest me
@_MadhviSharma
@_MadhviSharma 2 жыл бұрын
@@sabhavathyashwanth9145 you can follow this series, it would be really helpful for you. And in 3rd sem there is dsa subject, so you can prepare it smoothly.
@sabhavathyashwanth9145
@sabhavathyashwanth9145 2 жыл бұрын
@@_MadhviSharma thanks mam for your reply Mam which lang. is better for DSA C or C++. As per my clg syllabus we have DSA subject right in 2nd sem and OOPS in 3rd sem and prof. teaches us in C it seems
@cyberserker
@cyberserker 2 жыл бұрын
@@sabhavathyashwanth9145 Start with C and switch to C++ after you've done the Basic Data structures in C , that way your college syllabus will get covered. BTW C and C++ are not very different so you wont face any problems! :D
@_MadhviSharma
@_MadhviSharma 2 жыл бұрын
I had just completed the first phase of this series..thank you so much sir for such content. Please provide handwritten notes from 6th lecture onwards.
@sounaksaha1455
@sounaksaha1455 2 жыл бұрын
6th aur 7th ka aa gaya hai ji....... dekh lijiye
@_MadhviSharma
@_MadhviSharma 2 жыл бұрын
@@sounaksaha1455 thank you!
@sidtech10
@sidtech10 2 жыл бұрын
@@sounaksaha1455 handwritten notes kaha hai🤔
@udaypratapsingh8923
@udaypratapsingh8923 2 жыл бұрын
bhaiyaa aapka course dhoom machane vaala hai ...
@akashdeepmaity639
@akashdeepmaity639 Жыл бұрын
Taking 100 days DSA challenge from here on and going to comment in next videos everyday after completion........ Day -1 :: Completed
@ravivishvas3676
@ravivishvas3676 2 жыл бұрын
Incomparable efforts 🔥
@sounaksaha1455
@sounaksaha1455 2 жыл бұрын
Love you bhaiya... Hope everyone will get their dream placement
@manishabose8012
@manishabose8012 Ай бұрын
To those watching this video after this comment has been posted: the question 'Reverse List in K Groups' has been changed by CodingNinja (not sure why they did it). The solution in the video won't work completely; you need to reverse it again if the last group has fewer than k nodes to restore the original order. So, you’ll need to add a few more lines of code. Code: Node* kReverse(Node* head, int k) { int cnt = 0; Node* curr = head; Node* prev = nullptr; Node* fwd = nullptr; while (curr!=nullptr && cnt < k) { fwd = curr->next; curr->next = prev; prev = curr; curr = fwd; cnt++; } //You need to add this; Note: I have used the variable name fwd instead of next. if(cntnext = prev; prev = curr; curr = fwd; cnt++; } } //Till here if(fwd != nullptr){ head->next = kReverse(fwd, k); } return prev; }
@tjstar390
@tjstar390 2 жыл бұрын
Thank you bhaiya for giving fabulous content as both Question are very easy to understand.
@pushkarchaubey8300
@pushkarchaubey8300 2 жыл бұрын
bhut badhiya vedio tha bhaiya mazza aa gaya ekdamm mst smjh me aaya LL
@saiyamanand1387
@saiyamanand1387 2 жыл бұрын
Maaza aa rha hai karke coding ab bohot sahi chl rha hai sab jaldi jaldi bna do Bhaiya video ab
@aryanrathi1843
@aryanrathi1843 Жыл бұрын
After surfing many other youtube vedios , I watched this Vedio and the explaination of the first question in the vedio told by bhaiya is crystal clear. Crazyy!! and thanks for this kind of in-depth explaination it became like an very easy problem for me now.
@parassetia4964
@parassetia4964 2 жыл бұрын
Lec 46 done...consistency op
@kaushalkumar01
@kaushalkumar01 2 жыл бұрын
Thanks bhaiya....mza aa gya🔥🔥🔥🔥 Aapki yhi consistency hi to motivation hai hmare liye... Aise hi vids bnate rho bhaiya💜
@srajittanwar636
@srajittanwar636 2 жыл бұрын
PRESENT BHAIYA ,aap bhi josh high rakho humara bhi high h
@ln-gamer9496
@ln-gamer9496 Жыл бұрын
BHAIYA YOU ARE MY BEST TEACHER
@code___with___me
@code___with___me Жыл бұрын
in this question one case is missing like if the K is greater then the no. of elements in the linkedlist so we also need to count the elements in the linked list and have to made a condition that if(k>no. of elements in the linkedlist )then we will return head Node* kReverse(Node* head, int k) { if(head==NULL){ return NULL; } Node* prev=NULL; Node* forward=NULL; Node* curr=head; //checking whether the size of k is smaller then the size of the linkedlist int counter=0; Node* temp=head; while(temp){ temp=temp->next; counter++; } int count=0; if(k>counter){ return head; } while(curr && countnext; curr->next=prev; prev=curr; curr=forward; count++; } if(forward){ head->next=kReverse(forward,k); } return prev; }
@vikramlucky92
@vikramlucky92 8 ай бұрын
you can add another case to this part for little improvement: while(temp and counter < k){ temp=temp->next; counter++;
@ThePrajaktaVlogs
@ThePrajaktaVlogs 2 жыл бұрын
dekh rahe hai bhaiyya ! aur maja bhi aa rha h : )
@culeinfo3058
@culeinfo3058 2 жыл бұрын
yes keep uploading daily. love ur content
@makkar.ankush
@makkar.ankush Жыл бұрын
code for submission without errors regarding lenght less then k ``` Node* kReverse(Node* head, int k) { //base call if(head == NULL) { return head; } //step1: reverse first k nodes Node* next = NULL; Node* curr = head; Node* prev = NULL; int count= 0; // *ADDITIONAL CODE* // check if k nodes are available int check= 0; Node* Chk = head; while( Chk != NULL && check < k ) { Chk = Chk->next; check++; } // if not available then return head without reversing if(check != k){ return head; } // else reverse while( curr != NULL && count < k ) { next = curr -> next; curr -> next = prev; prev = curr; curr = next; count++; } //step2: Recursion dekhlega aage ke nodes ko // aur usko jod do pehle vale k sath if(next != NULL) { head -> next = kReverse(next,k); } //step3: return head of reversed list return prev; } ```
@scoc55vora15
@scoc55vora15 Жыл бұрын
Very Detailedfully Explained Bhaiya on the Entire youtube
@RohitRana-tz2lr
@RohitRana-tz2lr 2 жыл бұрын
Thanks bhaiya for your videos... crossed 50 videos... consistency++... mja aara h bhaiya
@nikhildhiman0714
@nikhildhiman0714 2 жыл бұрын
Bhiya apka motivation high h tabhi Mera bhi . App 3 video bno ge ma 3 hi dakh luga🥰🥰🥰
@shashnka
@shashnka Жыл бұрын
haaaaard love bhai watched till end🗣🗣
@ellis-pr7hh
@ellis-pr7hh 2 жыл бұрын
i wish and hope that your channel will grow more faster and aapka dsa course best dsa course over youtube consider kiya jaya (though i already consider that bt this course needs to be reached to lot of people) thank you for this course>>
@rajatjana
@rajatjana Жыл бұрын
For Leetcode: class Solution { public: ListNode* reverseKGroup(ListNode* head, int k) { if(head==NULL){ return NULL; } ListNode* next=NULL; ListNode* curr=head; ListNode* prev=NULL; int c=0; while (curr != NULL && c< k) { curr = curr->next; c++; } if (c < k) { return head; } curr = head; c = 0; while(curr!=NULL&&cnext; curr->next=prev; prev=curr; curr=next; c++; } if(next!=NULL){ head->next=reverseKGroup(next,k); } return prev; } };
@nana_patekar_
@nana_patekar_ Жыл бұрын
we can also solve circular LL question using Floyd's cycle detection bool isCircular(Node* head){ // Write your code here. //if head is NULL if(head==NULL) return true; //ony 1 node if(head->next==NULL) return false; Node *fast=head; Node *slow=head; while(fast->next!=NULL){ fast=fast->next; if(fast!=NULL) fast=fast->next; slow=slow->next; if(fast==slow && fast ==head) return true; else if(fast==slow && slow!=head) return false; if(fast==NULL){return false;} } return false; }
@RitikSingh-oh3sj
@RitikSingh-oh3sj 2 жыл бұрын
bhaiya iss lecture mai maga aa gaya bhaiya kaya mast code tha bahiya
@computerguy3550
@computerguy3550 Жыл бұрын
Thanks Alot bhaiya Ek Number Content👌👌👌👌
@prathammadhani4372
@prathammadhani4372 2 жыл бұрын
Attendance marked....thanks bhaiya for love babbar contest 4
@RahulKumar-wt9qc
@RahulKumar-wt9qc 2 жыл бұрын
Video banaiye love bhaiya hum log dekh rahe hai ❤️❤️👍👍
@krishnendubanerjee8523
@krishnendubanerjee8523 2 жыл бұрын
What if the list is: 1,2,3,4,5 and k=3. This approach won't work. Output should be: 3,2,1,4,5. But it will give you: 3,2,1,5,4
@karankaran1916
@karankaran1916 2 жыл бұрын
you can compare the length with k at start
@kunalboxer4432
@kunalboxer4432 Жыл бұрын
It will work try trail run
@sukhendubanerjee5082
@sukhendubanerjee5082 Жыл бұрын
​@@karankaran1916 but on calculating the rest part of LL we want to use loop then what will be the time complexity? Plzz explain and what will be the code ...
@anmol3
@anmol3 Жыл бұрын
​@@karankaran1916 thanks bro
@meghaiiitd4586
@meghaiiitd4586 Жыл бұрын
You can count the remaining elements from current, ListNode* remaining=curr & count=0; then if count>=k (recursion) else head->next=curr.
@Josuke217
@Josuke217 6 ай бұрын
map can also be used , if freq of a node is 2 then it's circular linked list.
@Harshji249
@Harshji249 2 жыл бұрын
Great video for linked list question
@manojalladawar2262
@manojalladawar2262 2 жыл бұрын
Done wih previous lecture and i'm with your phase. Full dedicate hai thanks for this amazing series. Thank you bhaya.
@bheemsingh-fh1zu
@bheemsingh-fh1zu 2 жыл бұрын
Bhaiya please daily video laado🥺🥺 Placement aapke bharoshe h. Mujhe aapse hi pdhna h😁
@sanskritiagrawal5960
@sanskritiagrawal5960 2 жыл бұрын
Bhaiya bas aise hi padhao bhot sahi chal raha h
@anushreepaul5308
@anushreepaul5308 2 жыл бұрын
raat ke 01.38 baj rhe hai.. still mai code kar rhi.. because of you vaiya.. 😁😁 Thank you sooo much :)
@arjunyadav-kt5jr
@arjunyadav-kt5jr 2 жыл бұрын
V kyu lagate ho be tumlog, bh ki jagah pe?
@gouravmuchhal1985
@gouravmuchhal1985 Жыл бұрын
i dont know how he breakdown things in so simple ..
@akash.vishwakarma
@akash.vishwakarma 9 ай бұрын
For those who don't have to reverse when length < k int getLength(Node* head) { int length = 0; while(head != NULL) { count ++; head = head -> next; } return length; } Node* kReverse(Node* head, int k) { if(head == NULL || head -> next == NULL) { return head; } if(getLength(head) < k) { return head; } Node* prev = NULL; Node* curr = head; int count = 0; while(curr != NULL && count < k) { Node* forw = curr -> next; curr -> next = prev; prev = curr; curr = forw; count ++; } head -> next = kReverse(curr, k); return prev; }
@iEntertainmentFunShorts
@iEntertainmentFunShorts 2 жыл бұрын
Completed this lecture also aap jab circular list wala bta rhe thy toh mere mind m aaya tha ki yei loop bhi ho sakta h yaha pr (mtlb logic bnna start ho gya h bhaiya ) then Floyd's ka toh pta ni muje but hash map se solve ho jayega woh...Floyd's dekhuga ab sayad graph m Maine warshall , Dijkstra and Floyd's pdi h wahi hogi...
@amarnathprajapati2543
@amarnathprajapati2543 Жыл бұрын
39:58 Bahut energy hai Sirji😂😂
@mananupmanyu5440
@mananupmanyu5440 Жыл бұрын
Updated code for reverse K nodes on @leetcode 30/30 test cases passed Node* kreverse(Node* &head,int k) { // base case if(head == NULL) { return NULL; } Node* curr = head; Node* prev = NULL; Node* forw = NULL; int cnt = 0; while( curr != NULL && cnt < k){ forw = curr->next; curr -> next = prev; prev = curr; curr = forw; cnt++; } // if the forward list's length is less than k than we simply // join the original list to the head if(getlength(forw) < k){ head->next = forw; } else if (forw != NULL && getlength(forw) >= k){ head -> next = kreverse(forw,k); } return prev; }
@priyanshusahoo8266
@priyanshusahoo8266 6 ай бұрын
We can also use concept of two pointers to check the circular LinkedIn list
@devsood12
@devsood12 Ай бұрын
updated solution for Q1 int sizeLL(Node *head) { Node*temp = head ; int cnt = 0 ; while (temp !=NULL ) { cnt ++ ; temp = temp->next ; } return cnt ; } Node* kReverse(Node* head, int k) { // Write your code here. int size = sizeLL(head ) ; Node * prev = NULL ; Node * curr = head ; Node * next = NULL ; int cnt = 0 ; if ( head == NULL || head -> next == NULL || k == 1|| size < k) { return head ; } while (curr!=NULL && cnt < k ) { next = curr->next ; curr->next = prev ; prev = curr ; curr = next ; cnt ++ ; } if (next != NULL ) { head->next = kReverse(next, k) ; } return prev ; }
@DILSHADKHAN-cv1qw
@DILSHADKHAN-cv1qw 2 жыл бұрын
for cll: bool checkcircular(Node *head) { if(head==NULL) //empty list return 1; Node *temp=head->next; while(1) { if(temp==head) return 1; if(temp==NULL) return 0; temp=temp->next; } }
@111rhishishranjan2
@111rhishishranjan2 Жыл бұрын
while (1) mean ??????
@DILSHADKHAN-cv1qw
@DILSHADKHAN-cv1qw Жыл бұрын
@@111rhishishranjan2 infinity loop (always true)
@jatingarg1897
@jatingarg1897 2 жыл бұрын
Dekhte Dekhte video bhai itni aage pahunchgaye ! :)
@absarahmad8625
@absarahmad8625 2 жыл бұрын
Bhaiya becuase of uh finally i learn how to think how to improve logic. thnx bhaiya
@bhavingargyt
@bhavingargyt Жыл бұрын
dekh rhe hai sir abhi bhi or khatam karke hi rahunga .... 🌟
@aparnamanna1369
@aparnamanna1369 2 жыл бұрын
Attendance marked , chalo lecture dekh te hai
@rawat_ji5183
@rawat_ji5183 2 жыл бұрын
nice explanation bhaiya easy to understand 😁😁
@somesh1934
@somesh1934 2 жыл бұрын
Present Bhaiya..... And thanq bhaiya but bhaiya aap ek he video daalo ek din ki kyonki doosri studies bhi rehti hai for example agr me meri he baat krun toh me python full stack k liye react,django vgera bhi pd rha hn toh mujhe unki bhi practice krna hoti hai toh load bht bd jata hai but haan first priority aapke liye hain then python full stack k liye so bhaiya bus.....Me toh mere point of view se bta rha hn jo baaki dusro ko accha lge ek din ki kitni video? majority wins.... And thanq so much bhaiya for the video....Waiting for the next video.....
@be_happy8411
@be_happy8411 2 жыл бұрын
bhayia main aaj k aaj ll khtm krna chahta hoon , currently 3 videos dekhli hain ab 4th start krne wala hoon. Motivation bnaye rkhne k liye aage ki hr video complete krke comments mein aapko msg kroonga 🥲, btw boht badhiya padha rhe ho aap😀👍
@Bhagwati_Jewellers.
@Bhagwati_Jewellers. 2 жыл бұрын
Bhaiya mjaa aa rha h 🙌
@rpgaming757
@rpgaming757 Жыл бұрын
Thanks bhaiya , this video is very helpfull for me
@suranjandhara7535
@suranjandhara7535 2 жыл бұрын
Aa gya hu bhaiya...... Present bhaiya 🤗🤗🤗🤗🤗🤗 Kal contest hai.....Accha nhi hoga pata hai... Firbhi dunga...😔😔😔😔😔😔 1 week follow kar raha hu bhaiya...🤗🤗🤗🤗🤗🤗🤗🤗😊😊😊😊😊 Love you bhaiya.... Amazing 😍😍😍😍😍 content
@adityasahoo506
@adityasahoo506 Ай бұрын
My Solution : whenever length>k from there we call a function to calculate remaining length. if remLenght>=k then we use recurrsion. otherwise just add head->next to curr ; class Solution { public: int calc(ListNode* curr){ int count = 0 ; while(curr!=NULL){ count++; curr = curr->next; } return count; } ListNode* reverseKGroup(ListNode* head, int k) { int length = 0 ; ListNode* prev = NULL; ListNode* curr = head ; ListNode* next = NULL; while(lengthnext; curr->next = prev ; prev = curr ; curr = next ; length++; } head->next = curr; int remLength = calc(curr); if(remLength >= k ){ head->next = reverseKGroup(next , k ); } return prev; } };
@04adarshsingh47
@04adarshsingh47 2 жыл бұрын
your way of explanation is really Good ❤
@abhishekjha0303
@abhishekjha0303 9 ай бұрын
Nice explanation bhaiya!
@Shantanu_Jod
@Shantanu_Jod 2 жыл бұрын
Following The course! 😄
@dewanshyadav6033
@dewanshyadav6033 2 жыл бұрын
Thanks bhaiyya 🙏🙏🙏🙏...
@AnuMessi10
@AnuMessi10 2 жыл бұрын
Do not stop bhaiya, lecture 37 par hu, will catch up soon
@sachin_singh_tomar_
@sachin_singh_tomar_ 10 ай бұрын
bool isCircular(Node *head) { Node* temp = head->next; while(temp){ if(temp==nullptr){break;} if(temp==head){return true;} temp=temp->next; } // Your code here return false; }
@balwantyadav724
@balwantyadav724 2 жыл бұрын
Nice explanation Bhaiya
@DheerajKumar-td5ts
@DheerajKumar-td5ts Жыл бұрын
Thank you bhaiya
@srinathsilla5800
@srinathsilla5800 2 жыл бұрын
Keeping up with the videos 👏🙌
@nikunjpadia2970
@nikunjpadia2970 2 жыл бұрын
Great Explanation Understood Everything.
@Divyansh-x7n
@Divyansh-x7n Жыл бұрын
bhot hard content bhaiyaaaaa >>>>
L21. Reverse Nodes in K Group Size of LinkedList
24:31
take U forward
Рет қаралды 102 М.
SIZE DOESN’T MATTER @benjaminjiujitsu
00:46
Natan por Aí
Рет қаралды 3,1 МЛН
Мама у нас строгая
00:20
VAVAN
Рет қаралды 11 МЛН
How to Fight a Gross Man 😡
00:19
Alan Chikin Chow
Рет қаралды 17 МЛН
Long Nails 💅🏻 #shorts
00:50
Mr DegrEE
Рет қаралды 16 МЛН
Why is Python 150X slower than C?
10:45
Mehul - Codedamn
Рет қаралды 16 М.
Reverse Nodes in k-Group | Among the toughest problems of LinkedList
20:05
Lecture 45: Linked List Questions: Reverse LL and find Middle of LL
52:40
CodeHelp - by Babbar
Рет қаралды 411 М.
NVIDIA’s New AI: Stunning Voice Generator!
6:21
Two Minute Papers
Рет қаралды 72 М.
Lecture 44: Linked List & its types - Singly, Doubly, Circular etc.
2:21:18
CodeHelp - by Babbar
Рет қаралды 1,6 МЛН
Reverse Nodes in K-Group - Linked List - Leetcode 25
12:20
NeetCode
Рет қаралды 114 М.
L11. Add 1 to a number represented by LinkedList
25:28
take U forward
Рет қаралды 76 М.
Beginners Should Think Differently When Writing Golang
11:35
Anthony GG
Рет қаралды 124 М.
Lecture 48: Remove Duplicates from a Sorted/UnSorted Linked List
27:25
CodeHelp - by Babbar
Рет қаралды 196 М.
SIZE DOESN’T MATTER @benjaminjiujitsu
00:46
Natan por Aí
Рет қаралды 3,1 МЛН