Babbar bhaiyya... I love you... Koii apna bhi itna help nhi karta jitna aap kar rhe ho.... Bhagwan aapko meri ummar bhi de de... Legend and GOAT....
@iamvishnuranjan2 жыл бұрын
Bhaiya 1 month me (1- 49 )lecture 😍 what a course..
@yashsonune43912 жыл бұрын
Glad I have completed 1/3 of the series, and still continuing.
@parthdeshwal44197 ай бұрын
how long did it take you ?
@Anmol-h8z5 ай бұрын
at 41:15 while inserting a node between two nodes we can use : curr1->next=curr2; curr2=curr2->next; curr1=curr1->next; curr1->next=next2; and also why we are checking for next1->data >curr2->data > curr1->data we could just check with next1 only as we know we start with element with smallest value any value will be greater than or equal from starting node and then going further in list if curr2 is inserted and then new curr2 value will definitely greater than previous one
@harshitkumar1972 жыл бұрын
I coded the 2nd one merge two sorted array by myself. i looked at ur approach discussion and did by myself. thanks for the giving me the confidence
@therealartist99 ай бұрын
in which company you are working ??
@tjstar3902 жыл бұрын
BOTH Questions have unique concepts and bhaiya explain it very well,Thanks bhaiya.
@RajveerKaur-ze1ll Жыл бұрын
to check for the case when both elements have one one element, instead of adding a new if condition at beginning, we can also move the "if (next1==NULL)" condition outside the while loop, then also answer is correct, hope this helps.
@prashantbpkumar510 Жыл бұрын
Exactly
@tanishsinghal187911 ай бұрын
yeah boyh
@priyanshpatel20782 жыл бұрын
20:00 We can Simply Handle it by using this steps p3->next=NULL; p2->next=twoHead->next; p1->next=oneHead->next;
@tusharmukherjeeju-cse57732 жыл бұрын
Can't believe that someone dislike this video ! 🙂 💔 If you buy a course which takes from you 20k that course never give you that kind of explanation . Love from Kolkata ❤️🙌
@divyareddy76222 жыл бұрын
why cant zero and two 's list be empty here? he only took the case when 1's list is empty
@visheshkaran7083 Жыл бұрын
@@divyareddy7622 because even if two's or zero's list are empty they will be null and onetail->next will be null so it won't make any difference.
@yashparalikar05 Жыл бұрын
Your teaching and your explanations are absolutely exceptional!!!
@unboxtheuniverse53362 жыл бұрын
Wahhh bhaiya 💥😃😃 DSA ki ab Video na dekhu to din productive nhi lagta 😃 Bhaiya plz *"5 Month Internship Strategy Series lao with DSA busted course as resource"* (for 2nd year students)🥺
35:00 Explanation was just amazing, thank you so much!
@anmolkumar01 Жыл бұрын
at 55:44 , i think we don't need to add extra case when there is only one element in list one instead what we can do is - we can simply write that condition of if(next1== NULL and curr2 != NULL){ curr1 -> next = curr2; } it will take care of case at 55:44 as well as previous case when first list finish and second list still has some element and please feel free to to correct me if i am wrong ,
@Josuke2176 ай бұрын
My approach: SC: O(n) , TC: O(n) For 0,1,2. class Solution { public: ListNode* sortList(ListNode* head) { vector res; ListNode* temp = head; while(temp != nullptr) { res.push_back(temp->val); // Store value of current node temp = temp->next; // Move to next node } sort(res.begin(),res.end()); // Sort the vector // Now convert the vector into the sorted linked list int index=0; temp = head; while(temp != nullptr) { temp->val = res[index++]; temp = temp->next; } return head; } }
@Roshanhoro1232 жыл бұрын
thanks bhaiya for bringing all such good questions in this course and hats off to your efforts...aap itne busy hoke bhi regular videos daal rhe ho isse motivation milta hai ki chahe kitne bhi busy rhe humlog cllg exams me tb bhi hum pdhai krre... Thanks bhaiya...Keep smiling bhaiya bht suit krta hai aaapar..
@devanshusahoo2 жыл бұрын
Thank you so much for your lovely videos, you really make understanding the concepts a cakewalk! Glad to be your student.
@divyareddy76222 жыл бұрын
why cant zero and two 's list be empty here? he only took the case when 1's list is empty
@suranjandhara75352 жыл бұрын
Wow 😳😳😳😳😳 nya video aa gya..... Maza aa gya .... Abhi hi dekh lunga....🥰🥰🥰🥰🥰🥰🥰❤️❤️❤️❤️❤️❤️❤️❤️❤️🌷🌷🌷🌷🌷🌷🌷🌷🌷 Thanku bhaiya .... ❤️❤️❤️❤️
@mittalji9193 ай бұрын
i used below merging algo and it is also working without any if condition nodeZTail->next = nodeO->next; delete(nodeO); nodeOTail->next = nodeT->next; delete(nodeT); head = nodeZ->next; delete(nodeZ); return head;
@115GAJBHIYESHREYA2 ай бұрын
Thank you for providing an amazing series.
@StayAware92 жыл бұрын
Itna cylister clear hogaya question and approach Oye hoye hoye Jug Jug Jio bhai!!!
@anmolkumar01 Жыл бұрын
my approach for 1st question was that i just sorted it in two go without using extra space and in O(n) firstly : sort all the ones , if one present then remove it and link it to the head of list and update the head secondly : sort all the zeros , if 0 is present then remove it and link it to the head of list and update the head my code : void sort(Node* &head , int val){ Node* temp = head; while(temp->next != NULL){ if(temp->next->data == val){ Node* x = temp->next; temp->next = x->next; x->next = head ; head = x; } else{ temp = temp->next; } } } Node* sortList(Node *head){ if(head == NULL or head->next == NULL) return head; sort(head , 1); sort(head , 0); return head; } if there is any suggestion or correction then please feel free to correct me and above code is also accepted by the codestudio
@vmstudy996510 ай бұрын
Mjaa aa gya bhiya aaj to🎉 Finally I solved this problem myself. After watching this video
Sir in question 2 : If first -> next == NULL then answer will note come.. Please add another condition- if(first -> next == NULL) { first -> next = second; return first; }
@tanbirsarkar2640 Жыл бұрын
sabse maza to linked list mai arha hai,,mast hai bahut,,basss pyar hojata hai
@kanikagupta28062 жыл бұрын
concept++; understanding +++++++++; thankyou so much babbar bhaiya maza hi aagya..
@divyareddy76222 жыл бұрын
why cant zero and two 's list be empty here? he only took the case when 1's list is empty
@kanikagupta2806 Жыл бұрын
@@divyareddy7622 beacuse 1's list is connecting 0's and 2's list. If 1's list is empty then approach discussed without if condition won't work. Hope it helps.
@Pawankumar-i8c4 ай бұрын
thank you so much bhiaya for these precious lecture
@theOmKumar2 жыл бұрын
Explanation + Minor adjustment to improve q1 while addressing memory leak! // // merge 3 sublist (assuming one's list is not empty) zeroTail -> next = oneHead -> next; oneTail -> next = twoHead -> next; twoTail -> next = NULL; return zeroHead -> next; //merge 3 sublist (Note: if 1st list is empty, then we can't connect zero list with two list using previous code) if (oneHead -> next != NULL) //one's list is not empty, so we'll connect 0 list with one { zeroTail -> next = oneHead -> next; oneTail -> next = twoHead -> next; } else zeroTail -> next = twoHead -> next; //one's list is empty, so we'll connect 0 list with 2s directly; twoTail -> next = NULL; //this will end the LL. return zeroHead -> next; // //to prevent memory leak, due to allocation of dummy node so we need to delete it. // Node* ans = zeroHead -> next; // delete(zeroHead); // delete(oneHead); // delete(twoHead); // return ans; }
@lakshsinghania Жыл бұрын
exactly! kudos
@arpitghura Жыл бұрын
this is what I am supposing as the oneHead does not have any one node, so if we put it outside it will create an additional LL which is of no use. So, we can put the line no. 60 inside the if condition to prevent the creation of additional LL.
@tanishsinghal187911 ай бұрын
shi hai bhai agr tu comment m nhi likhta ye sb to mai ye sochta syad m hi glt hun
@adityachauhan59132 жыл бұрын
@codeHelp bhaiya ek dummy node le kr compare aur direct connect karte chale jaaye last me dummy ka nxt return kar dnge
@KaushikSharma-c3q Жыл бұрын
Awesome explanation.
@kunalmodiart2 жыл бұрын
more easiest way to code Q2 would be to use 2 pointers pointer pointing smallest element gets added at the end of ansLL //============================================= Node* solve(Node* first, Node* second){ Node* ans=new Node(-1); Node* anstail=ans; Node* fhead=first; Node* shead=second; while(fhead!=NULL&&shead!=NULL){ if(fhead->datadata){ anstail->next=fhead; anstail=anstail->next; fhead=fhead->next; }else{ anstail->next=shead; anstail=anstail->next; shead=shead->next; } } while(shead!=NULL){ anstail->next=shead; anstail=anstail->next; shead=shead->next; } while(fhead!=NULL){ anstail->next=fhead; anstail=anstail->next; fhead=fhead->next; } anstail->next=NULL; return ans->next; } Node* sortTwoLists(Node* first, Node* second) { if(first==NULL){ return second; } if(second==NULL){ return first; } return solve(first,second); } //=============================================
@adityaraj-zm7zk2 жыл бұрын
bhai it is very good question and you really very good explained , fanstically you are very good teacher
@sachitdhamija18842 жыл бұрын
bhaiya acha tha merge 2 sort L.L samjaha but sort 0,1,2 thoda problem hua but 2 baar aur dekho ga toh samjho ga lage raho
@vaibhavraj2847 Жыл бұрын
bhaiya aapne jo array me merge and sort wala concept se padhaya tha ussejyada easy se ho gaya!! #include #include using namespace std; class node { public: int data; node *next; node(int data) { this->data = data; this->next = NULL; } ~node() { int value = this->data; if (this->next != NULL) { next = NULL; } delete next; cout next = curr2; tail = curr2; curr2 = curr2->next; } } while (curr1 != NULL) { tail->next = curr1; tail = curr1; curr1 = curr1->next; } while (curr2 != NULL) { tail->next = curr2; tail = curr2; curr2 = curr2->next; } head = head->next; return head; } int main() { node *head1 = NULL, *head2 = NULL; node *tail1 = NULL, *tail2 = NULL; insert(1, head1, tail1); insert(3, head1, tail1); insert(5, head1, tail1); insert(8, head1, tail1); insert(2, head2, tail2); insert(4, head2, tail2); insert(5, head2, tail2); insert(8, head2, tail2); insert(10, head2, tail2); print(head1); print(head2); node *ans = merge_two(head1, head2); print(ans); }
@verma_jay Жыл бұрын
Bhaiya bhot acha pdhate ho aap
@aishavkhandelwal82712 жыл бұрын
Mst ques tha dimag khul diya pura !! thx
@alokranjan31852 жыл бұрын
totatly different explanation bhaiya, thanks
@himanshugaur6790Ай бұрын
Another Approach to merge two sorted linked list Node* sortTwoLists(Node* first, Node* second) { Node* dummynode = new Node(-1); Node* temp = dummynode; while(first!=NULL && second!=NULL){ if(first->datadata){ temp->next = first; first = first->next; } else{ temp->next = second; second = second->next; } temp = temp->next; } if(first!=NULL){ temp->next = first; first = first->next; } else if(second!=NULL){ temp->next = second; second = second->next; } return dummynode->next; }
Mere dekhne ki consistency se jyadaa toh video aane ki hai..
@itz_arman_official__2 жыл бұрын
Thanks for your amazing content and your consistency is awesome bhaiya.
@anuragpandey81652 жыл бұрын
37:10 Just call sortTwoList(second, first) thats it.
@justarandomguy61062 жыл бұрын
How's that possible
@AWAISKHALID-ze5cw Жыл бұрын
the second approach could as to create a new head and make the new links after checking each data for the current pointer. it would create a new organised link with the previous one
@Hit-xe5uh11 ай бұрын
Can't we simply apply selection sort in the first question?
@lalitbisht8381 Жыл бұрын
merge wala question krke maza aa gya!!!!!!!!!!
@RitikSingh-oh3sj2 жыл бұрын
merge walai second question mai maga aa gaya bhaiya
@B-NikhilRichhariya Жыл бұрын
aap mehnat krte ho na wo dekh ke aur mehnat krne ka mn krta hai
@arvindjindal1913 Жыл бұрын
ham second question mai ek nai list ans banakr aur usme koi value like -1 dekr phir jo first aur second mai jo chota hai usko ans list se link nhi karva sakte aur return karvate waqt ans ke next se return bhi toh karva skte h
@abhishekhsinha155110 ай бұрын
glad for your kind help moye moye !!! love from IITG
@prashantbirajdar92712 жыл бұрын
ha bhaiyaa smja aya ache se ekdum bdiya❣😾❤
@samsmith39612 жыл бұрын
concept finally samajh aa gya
@garimasharma276 Жыл бұрын
NEVER have I ever got such a crush on some one!! your way of teaching is quite captivating.
@princekatare53992 жыл бұрын
Bhaiya at 21:20....... instead of writing the if conditions like this..... if(oneHead->next != NULL) { zeroTail -> next = oneHead->next; } else { zeroTail -> next = twoHead->next; } oneTail->next = twoHead->next; We can write the code........ in the following order oneTail->next = twoHead->next; zeroTail -> next = oneHead->next; (we first link the twoHead to oneTail and then oneHead to zeroTail......) anyone please correct me if i am wrong...... And also thank you for the playlist bhaiya the DSA series is awsome and really helpful....
@muneebjaved39402 жыл бұрын
Thank you so much bhayia Concept ++++++; Explanation ++++++++;
@anuptewary30162 жыл бұрын
Present bhaiya with lot's of Josh
@riyadhossain1706 Жыл бұрын
Became a fan of your learning style...........
@StayAware92 жыл бұрын
add a thanks button we want to pay you for your good work! ❤❤❤❤❤❤❤
@RohitSingh-hc8yi Жыл бұрын
2nd Problem was awesome!
@RohitSingh-hc8yi Жыл бұрын
Thankyou for such a quality content
@rishikbisen42682 жыл бұрын
it also one approach to solve problem 💥💥💥💥💥💥 Node* sortedMerge(Node* head1, Node* head2) { if (head1==NULL) return head2; if (head2==NULL) return head1; if (head1->datadata) { head1->next=sortedMerge(head1->next, head2); return head1; }else { head2->next=sortedMerge(head1,head2->next); return head2; } }
@salmankhader1258 Жыл бұрын
small idea , if we put the condition which babbar wrote just before ending of while loop in the starting of the loop then it will handle the code for edge cases like if we have only one Node in our first list hence no need to write the seperate if condition for that edge case.
@shishirkj Жыл бұрын
can u explain this more plz
@sarthakmoriya5412 жыл бұрын
what is Node can anyone please tell???
@ritikamehta97912 жыл бұрын
Great work sir!! mza aa rha hai ab pdhne me💯
@kundanmali2405 Жыл бұрын
thank you for providing such great content.
@Engineering_Unlocked4 ай бұрын
thnx bhaiya :) completed on 8/7/24
@theOmKumar2 жыл бұрын
Simpler Approach for Q2. , we can also do this without dummy node by putting head at right place first , and then simply traversing and joining smaller val data. ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) { if (!list1) return list2; if (!list2) return list1; ListNode *ans = new ListNode(-1); ListNode *temp = ans; while (list1 && list2) { if (list1->val < list2->val) { temp -> next = list1; temp = list1; list1 = list1 -> next; } else { temp -> next = list2; temp = list2; list2 = list2 -> next; } } while (list1) { temp -> next = list1; temp = list1; list1 = list1 -> next; } while (list2) { temp -> next = list2; temp = list2; list2 = list2 -> next; } return ans -> next; }
@kunalmodiart2 жыл бұрын
i watched the solution given in the video then went on to code the Q by myself with my approach .. then i came in comments to add my code and i found your code which is literally similar to mine 😂 what a coincidence
@antrikshgupta1964 Жыл бұрын
void sort(Node* &tail, Node* &head){ tail->next = head; head = head->next; tail = tail->next; } //Function to merge two sorted linked list. Node* sortedMerge(Node* head1, Node* head2) { Node* head = new Node(-1); Node* tail = head; while(head1!=NULL and head2!=NULL){ if(head1->data data){ sort(tail,head1); } else{ sort(tail,head2); } } while(head1!=NULL){ sort(tail,head1); } while(head2!=NULL){ sort(tail,head2); } return head->next; }
@priyanshujain8622 жыл бұрын
Amazing bhaiya 🤩🤩
@pahaljain9209 Жыл бұрын
Hat's Of bhaiya
@neerajgarg90962 жыл бұрын
EAGERLY WAITING FOR THIS LECTURE LOVE U BABBAR BHAIYA❤❤
@ch0c0_1 Жыл бұрын
mza aagya bhai . Nice explanation
@saurabhmalviya1002 жыл бұрын
Kya baat hai mazaa aa gaya .josh is high and it should be High 😂😂😂
@saswatighosh31622 жыл бұрын
It was lit 🔥🔥🔥🔥🔥🔥🔥
@HemantNavlani Жыл бұрын
In 1st question if we have made three sub lists of 0 1 and 2 in approach 2 would it not account for extra O(N) space ??
@ritik88792 жыл бұрын
attendance marked . bhaiya if possible video thoda jaldi jaldi daalo plz . my career depends on you
@sundrmm035011 ай бұрын
Bhiyaaaa!!! Uh beauty🙇🏻♂️
@divyanshupal1102 Жыл бұрын
if 0 empty or 2 empy then ?? there should be conditon for that also na???
@Dharmikmonk2 жыл бұрын
Bohot aachi vdo hai bhaiya
@ayushp44712 жыл бұрын
BEST explaination as always 🔥🙌
@jatingarg18972 жыл бұрын
Maza Aaayaa bhai karke !
@sushantgupta47572 жыл бұрын
you are the best bhaiya
@aadityagupta3720 Жыл бұрын
in first question we can use dutch national flag algo also
@anuragpandey81652 жыл бұрын
24:52 insertAtTail function kaha defined hai??
@shripandey41202 жыл бұрын
Bhaiya, 27:05 pr space complexity o(1) kse hogi, humne jo alag se three linked list bnayi hai uska space ?
@muhammadasimsaeed25689 ай бұрын
Can someone explain to me why at 22:31 in line 60 we are connecting one->tail to twoHead->next as we have already connected zeroTail to 1's List in if condition and zeroTail to 2's list in else condition, Thanks in advance