For those who can't understood the Approach 3 code of Reversing Linked-List (Recursively), Let's go through an example with a diagram to help illustrate the process. Suppose we have the following singly-linked list: 1 -> 2 -> 3 -> 4 -> 5 -> NULL To reverse this list, we can use the given code. 1. Initially, the `reverseList` function is called with the head of the list (`1`). 2. Inside the `reverse1` function, the base case is not met because the head is not `NULL` and it has a `next` pointer. 3. The `reverse1` function is recursively called with the next node (`2`) as the argument. 4. The process continues until the base case is met when we reach the last node (`5`) in the original list. 5. At this point, the recursion starts to unwind. Let's see the state of the list at each step: Step 1: chotaHead = 5 (the last node) Original list: 1 -> 2 -> 3 -> 4 -> 5 -> NULL Step 2: chotaHead = 5 Current node (head) = 4 Reverse the link between 4 and 5: 4 next = NULL to remove the link to the next node: 4 -> NULL Return chotaHead (5) Step 3: chotaHead = 5 Current node (head) = 3 Reverse the link between 3 and 4: 3 next = NULL: 3 -> NULL Return chotaHead (5) Step 4: chotaHead = 5 Current node (head) = 2 Reverse the link between 2 and 3: 2 next = NULL: 2 -> NULL Return chotaHead (5) Step 5: chotaHead = 5 Current node (head) = 1 Reverse the link between 1 and 2: 1 next = NULL: 1 -> NULL Return chotaHead (5) 6. The `reverseList` function now returns the new head of the reversed list, which is `chotaHead` (5). 7. The reversed list is: 5 -> 4 -> 3 -> 2 -> 1 -> NULL I hope this helped... Happy Coding✌
@darshnitwarangal Жыл бұрын
thnk u so much bhaiya gr8 explanation
@rajahindustani5771 Жыл бұрын
Awesome bro
@amanasrani6405 Жыл бұрын
thanks you so much , i can't undersastand this method through the vdo
@njcoder2641 Жыл бұрын
hats off bhaiya .. You clear my doubts in only two steps :)
@thecap724911 ай бұрын
Bro one doubt how are we going to generate this approach ?
@virendrakeshri60722 жыл бұрын
You are working two hard i am first year student in chitkara university and following all videos thanks bhaiya
@BornHubisLive2 жыл бұрын
Great dude keep it up.... I'am also.. In Chitkara 😂😂
@thakurtech0167 Жыл бұрын
Cgcian's are also there bro
@priyavratatiwari7788 Жыл бұрын
Bhai waise one hard kaise work karte hai? 😂
@sahilsingh1649 Жыл бұрын
@@priyavratatiwari7788 two hard se addhe time me
@vikaskumarsingh680710 ай бұрын
Kitna pdh lia DSA
@yashahuja155010 ай бұрын
void reverse(Node *head,Node *tail,int n) { Node *i=head; Node *j=tail; for(int k=0;kdata,j->data); i=i->next; j=j->previous; } swap(head,tail); return; } my approach thnk u bhaiya for making me this much capable
@SurajKumar-by9fh7 ай бұрын
Good one brother....
@SurajKumar-by9fh7 ай бұрын
Atlast you don't need to swap head and tail bro
@mamonigogoi38702 жыл бұрын
Following your series till this lecture, I got an internship in a Noida based company. Thank you so much bhaiya!! It was all because of you.. Please keep up the good work.. Can't thank you enough 🙏🙏🙏🙏
@icecoldnobody34472 жыл бұрын
wow bhai....kisme aaya..?nd what is the pay structure..+ are u still a student? which yr?
@AkshayGoel-of8ic Жыл бұрын
bhai please mujhe bhi help kar do, internship lagane mai please
@shalinijha73592 жыл бұрын
bhaiya shi me confidence aa jata h appke solution dekh k .. you motivate us a lot and aap mere inspiration ho
@sahilbheke40832 жыл бұрын
at 42:13 we can simply assign middle = (n/2)+1 and cnt=1;
@anmol3 Жыл бұрын
Right
@rajgopalsahu Жыл бұрын
for the 2nd problem(finding the middle) you can simply write //APPROACH 2 Node *findMiddle(Node *head){ //if the list has no nodes or a single node if(head==NULL || head->next==NULL){ return head; } Node *slow=head; Node *fast=head; while(fast!=NULL && fast->next!=NULL){ slow=slow->next; fast=fast->next->next; } return slow; }
@yashahuja155010 ай бұрын
right bro
@vitaminprotein22172 жыл бұрын
Middle of a linked list ez two pointer sol (two pointer approach) ListNode *slow = head, *fast = head; while(fast && fast -> next){ slow = slow -> next; fast = fast -> next -> next; } return slow
@POTNURURAHULADITHYA5 ай бұрын
@vitaminprotein2217 in approach 1 why didn't he use a reference variable in the case of head pointer .
@viveksinghgulia8739 Жыл бұрын
My code for the finding the middle of the linked list(I think it is cleaner) Node *findMiddle(Node *head) { Node *fast = head; Node *slow = head; while(fast && fast->next) { fast = fast ->next ->next; slow = slow->next; } return slow; }
@anmol3 Жыл бұрын
Your code is faster
@torus1512 жыл бұрын
apne last video ma concept aise samjaya tha ki questions ka approch already dimag ma aagaya tha.....thanks alot for such explination
@Abhishek-ji6qj5 ай бұрын
Bhai Zabardast Boss Esi explaination ho to DSA bahut simple lagta hai. Other channels pe bhi search kia lekin crystal clear yha aa ke hi hua.
@akashprajapati23932 жыл бұрын
Sir you are best teacher of dsa on youtube in my life . Sir charan sparse. From ncr.
@venugopalaniyengar35502 жыл бұрын
According to my experience till now... I would rather work in a challenging place where I have to think a lot and make mistakes and write code than do runt work like creating reports with already made software... Am loving the series bhai... following it religiously... I will give you a nice party when I get placed with > 40 lpa... Results await!! Love you bhai for this awesome step by step but slightly challenging journey ever!!!
@yashsawalkar646 Жыл бұрын
lagi kya plaement ?
@top_10_2.O Жыл бұрын
lgii??
@abhishek6575 Жыл бұрын
lagi kya
@AkshayGoel-of8ic Жыл бұрын
please tell
@priyamprakash120911 ай бұрын
lgi kya
@seniordevtuts2 жыл бұрын
sir if you need any help or support related to anything just say only once we are here for you. you are a best tutor
@akashbiswas86392 жыл бұрын
internship dedo vro
@AkshayGoel-of8ic Жыл бұрын
@@akashbiswas8639 aapki lag gayi? ab toh 1 saal ho gya, please meri help kar do
@tanyakansal4652 жыл бұрын
I think separately handling the cases for linked list length = 0,1,2 are not required. We can directly write the logic.
@HARRY-xz1hf Жыл бұрын
Thanks Babbar bhai.. Your videos are really easy to understand and provoke new approaches in our minds. Thanks a lot.
@anushkayachit2 жыл бұрын
attendance marked sir!!! really enjoying the course🖤🖤
@satvikshukla5962 жыл бұрын
I wish I could work as hard as you 😂 Thank you for all the efforts 🙏
@shubhamrathod66342 жыл бұрын
u will
@raygod1441 Жыл бұрын
@@shubhamrathod6634 hopefully I'll too
@AnkitKumar-js9rx Жыл бұрын
My code for homework (for reference I used the 2nd recursion approach for the reverse singly linked list from the video and modified it to update previous pointer of the node as well): Node* reverseDoublyLinkedList(Node* head) { if(head == NULL || head -> next == NULL) { return head; } Node* newHead = reverseDoublyLinkedList(head -> next); head -> prev = head -> next; head -> next -> next = head; head -> next = NULL; return newHead; } It works but if you could confirm that I'm not wrong here, actually didn't put much time into it so I'm doubtful about it.
Really outstanding contents bhayia. Understand All approaches crystal Clear just because of you.
@unboxtheuniverse53362 жыл бұрын
Abhi hi bhaiya just LL ki 2 ghante ki video complete kri he 😃 Now .... It's Tea time 🥱😂 Abb ye raat me dekhuga 😃😃 2 ghante ke lecture dekhne par bhi Borr nhi hota just bcz of you . #BeliveInBabbar Your Explanation is Always OP 🔥
@akash.vishwakarma8 ай бұрын
Orr bhai?? 2 saal ho gye... ky ky seekha?
@tayyabsami258 Жыл бұрын
The word Love in your name holds a specific place in my heart 🥺
Just finished the previous one and was waiting for this finally its here !😀🔥
@divyanshsen65732 жыл бұрын
This channel is sheer brilliance and exceptional epitome of the fantabulous knowledge and learnings. KUDOS to you LOVE BABBAR bhiya 🙌
@keshavarya79182 жыл бұрын
Bhai kripya iska Hindi anuvaad kar dijiye😅
@divyanshsen65732 жыл бұрын
@@keshavarya7918 zyaada ho gya kya😂
@divyanshsen65732 жыл бұрын
@@keshavarya7918 bass sir ko , bhawnao mai aake dil se shukriya kaha hai.
@keshavarya79182 жыл бұрын
Pata hai bhai 😂😂 Maze le raha tha
@AkshayGoel-of8ic Жыл бұрын
@@divyanshsen6573bhaiya aapki job lag gayi? Please meri thoda internship dhoodne mai help kar dijiye
@033_rajatsingh2 Жыл бұрын
The way you taught the approach 2 of 2nd question was 🔥🔥
@RAZERRUG2 жыл бұрын
attendance marked sir jiii !!! really enjoying the course🖤🖤
@kailashdaata86102 жыл бұрын
more optimized code for middle of linked list : public static Node findMiddle(Node head) { Node slow = head; Node fast = head; while(fast != null && fast.next != null) { slow = slow.next; fast = fast.next.next; } return slow; }
@priyanshu_-_2 жыл бұрын
In the even length LL it will not print the correct O/P....e.g. in 1->2->3->4->5->6....it'll print 3 but correct ans should be 4 !!
@sparsh21202 жыл бұрын
@@priyanshu_-_ Intialy: slow=1; fast=1; 1st jump: slow=2; fast=3; 2nd jump: slow=3; fast=5; Still fast->next!=null; 3rd jump: slow=4; fast=null; Return slow..... M I right or wrong????
@vats46842 жыл бұрын
@@sparsh2120 absolutely right. I think priyanshu interpreted it wrong. The code works
@RohitRana-tz2lr2 жыл бұрын
Thanks bhaiya for explaining linkedin question in so much depth .... attendance marked bhaiya... mja hi aa gya
Head - next - prev will not update i think for last node
@nischayagrawalVlogs Жыл бұрын
Approach 3 of Reversing linkedlist is the proper "recursive" way otherwise the 2nd method was just like the iterative way. If you could understand the 3rd approach then you have a bright future in trees and advance topics
@sachitdhamija18842 жыл бұрын
bhaiya aise hi bhaut saare approch aur question baate raho
@suranjandhara75352 жыл бұрын
Aa gya hu bhaiya.....Abhi college ka online class chal raha hai... Iska complete hone ke bad hi aap ka ye video dekhunga.... Mai to subha se hi aap ka lecture dekh raha hu....mast hai.... I am in OOPS 2... Now..... I will complete it then I will watch this... Thank you bhaiya for providing such amazing content 😘😘😘😘😘😘😘❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️
@NiteshKumar-qp7oy2 жыл бұрын
Thanks bhiya 🤗 mai bahot sare videos dekha hun put apke name sehi lgta ki video achi hogi 😌
Sir do make a practice sheet to solve all the important questions of linked list.!!✌
@divyanshuupadhyay98312 жыл бұрын
Middle of LL - code with better run time🙃🙃🙃 int n = 1 ; Node* ans = head; while(head->next != NULL){ head = head->next; n++; if(n%2==0) ans = ans->next;} return ans;
@keshavarya79182 жыл бұрын
Bhaiya jab OS series shuru hui (or COVID vala issue bhi) to is series ki consistency thodi kam ho gayi thi, tab doubt ho raha tha ki kya chal raha hai 🤔🤔🤔 Par pichle 3 din me aap nahi jaante kitni rahat mili hai😁😁😁 Sandeh karne ke liye maafi #BelieveInBabbar
@JatinKumar-w7f8 ай бұрын
well it is needed to take that condition if(head->next->next == NULL){return head->next;} because if the list has only two element so in this case second element would be our middle
@shyamparoha42368 ай бұрын
great teaching bhaiya bhautt ache se smj aagya aur last apporach me jo base case hai 2 node ke liye vo jarurui ni hai
@nancysinghal97672 жыл бұрын
Thanks bhaiyaa......your hard work matters...... Present bhaiyaa 🙋♀
Bro instead of writing current->pre=current->next; you can write " current->pre=forward" also i saw on vs code it is working , as link is not broken cause we have not assigned the current's next link to prev (NULL) we have the access for it . I was a bit Stuck But Your solution helped me . Thanks!!!!
@aravchauhan9186 Жыл бұрын
why are u taking a second prev when in dll there is already a prev defined in the class ,shouldn't it be named something else.
h.w--- to reverse a doubly linked list void reverse(Node* &head){ int l=len(head); int cnt=1; while(l>cnt){ head=head->next; cnt++; } cnt=0; while(l>cnt){ cout
@sounaksaha14552 жыл бұрын
Hum support karte hai, bhaiye..... dil se support karte hai....... kudos to your efforts
@anuptewary30162 жыл бұрын
Present bhaiya with lot's of love and support to you ❤️🔥
@iEntertainmentFunShorts2 жыл бұрын
Completed 2nd lecture on linked list
@manishrawat37912 жыл бұрын
bhaiya course consistency on it's peak
@abhyaskanaujia38622 жыл бұрын
Thank you so much for all of your efforts. Please take care of your health too.
@SriniVas-mx1li2 жыл бұрын
Thanq bhai for the wonderful content 🥳🌟 Attendance from Andhra Pradesh 🥳 Present Sir!
Love bhaiya to small linked list - "Chhoti LinkedList Ho Kyaa!!" . Jokes apart Seriously awesome lecture bhaiya.
@prashantbirajdar92712 жыл бұрын
mast bhaiyaa badhiya ekdum❤ sub smj aya🤩👍🙌
@_SHUBHANKARJENA2 жыл бұрын
attendance marked. nice video
@rachit_joshi8 ай бұрын
Thank You So Much BHRATA SHREE !!!!!!!
@chaitanyasawant7762 жыл бұрын
Eagerly waiting for this thank you bhaiya
@tannubansal17182 жыл бұрын
Consistency++++.. thankyou bhaiya ❤️
@striverop2 жыл бұрын
GALAT INCREMENT KR DIYA ERROR AA JAYEGA😂😂
@B-NikhilRichhariya Жыл бұрын
nhi wo do node wale ko check krne ki zarurt nhi agar do nodes rahi toh slow ek aage badhega, fast ek aage badhega but ek aur nhi badh paayega cause ab wo NULL ho chuka hoga and 2 even nodes h toh middle m right wala ie second node jispe slow aa chuka h wo answer hai toh algo waha bhi kaam krega
@03_abhishekchoubey422 жыл бұрын
Thanks bhiya for your amazing explanation it really helps me a lot😍
@ayanshijnn102824 күн бұрын
2 nodes wala case chalane ki koi need nhi h because the first thing is question me bol rahka h ki head ki farther node hi mid node hogi
@VivekYadav-ir2qf2 жыл бұрын
Excellent bhaiya. Thanks bhaiya for ur all efforts 💕💕
@anishbarnwal5676 Жыл бұрын
Thankyou bhaiya for this awesome lecture
@ancymaria39072 жыл бұрын
Hi love...subtitles are not available for the previous two videos..kindly pls add subtitles
Bhaiya please linked list ke topic me alag se question ki video ya list share kr dijiye
@coderwork8335 Жыл бұрын
Are bhai thank u bhai bohot badiya
@jaspreetpannu42642 жыл бұрын
attendance marked!!! mja aagya
@PRIYANSHUKUMAR-un9zu2 жыл бұрын
Thanks brother Present bhaiya 🔥❤
@piyush_kashyap232 жыл бұрын
Thank you bhai❤ 2:00
@umangsachdeva99202 жыл бұрын
Wah bahiya apne toh ek do din ki moj kra di😅🤣🤣 Ab toh ek hafta moj se katega👍👍🤗😝
@jaydwarkadhish9592 жыл бұрын
Sir amazing video
@rohankumarmainali2662 жыл бұрын
Little optimization on Middle of LL // if we take fast = head instead of fast = head -> next then there is no if condition required class Solution { public: ListNode* middleNode(ListNode* head) { if(head->next ==NULL) return head; if(head->next->next == NULL) return head->next; ListNode * slow = head; ListNode * fast = head; while(fast!=NULL && fast->next!=NULL){ slow = slow->next; fast = fast->next->next; } return slow; } };
@iutkarshmehta2 жыл бұрын
Attendance marked Reach++
@deepikarani46252 жыл бұрын
mst bhaiya aaple hi bta dijiye ki add hai ye acha lga
@priyanshugoyal25392 жыл бұрын
Present Bhaiya Ji
@sagarsharma76712 жыл бұрын
Thanx a lot bhaiya from the bottom of my heart ❤
@sachitdhamija18842 жыл бұрын
best time : 15:27 kyu good last time :bhi mast
@Ayush_.2 жыл бұрын
Babbar Bhaiya 5 month INTERNSHIP STRATEGY Series laao plzzz DSA busted course ko as Resource rakhkar
@amishapandey6875 Жыл бұрын
Well explained!
@KAMLESHGURJAR-y3z4 ай бұрын
babbar sir ki jai ho
@I_Anupam_Pandey2 жыл бұрын
Lecture 45 attendance thank you bhaiya for uploading daily 1 hour video