Unbelievable! How are you so so good bhai? Java Implementation: class Solution { private ListNode mergeTwoSortedList(ListNode l1, ListNode l2) { if(l1 == null) return l2; if(l2 == null) return l1; if(l1.val l2.val) { l2.next = mergeTwoSortedList(l1,l2.next); return l2; } return null; } private ListNode paritionAndMerge(int s, int e, ListNode[] lists) { if(s > e) { return null; } if(s == e) { return lists[s]; } int mid = s +(e-s)/2; ListNode L1 = paritionAndMerge(s,mid,lists); ListNode L2 = paritionAndMerge(mid+1,e,lists); return mergeTwoSortedList(L1,L2); } public ListNode mergeKLists(ListNode[] lists) { int k = lists.length; if(k == 0) { return null; } return paritionAndMerge(0,k-1,lists); } }
@GghiggFfhhhf5 күн бұрын
15 min ke baad khud se, code likh ke submit and got accepted the way he explain 🙏🙏😻😻
@itsaayush73573 ай бұрын
Clear, concise and simple explanation!! India has some unique talents. When it comes to code so we have best of best teachers available. In every domain there is one king, and in DSA we have our mik.
@guptajiivlogging8174 Жыл бұрын
Please bhaiya, it's my humble request to you please don't stop teaching dsa and cp and posting videos on solving question.. It help's a lot. After 5-6 months companies are going to visit our college so you and your channel is going to help me and my friends alot....Lots of love from jabalpur (MP)
@souravjoshi2293 Жыл бұрын
Same bro
@nawazthezaifre88709 ай бұрын
placement hoa kya bhai ??
@22gauravkumar705 ай бұрын
@@nawazthezaifre8870 placement hua?
@shweta10137 ай бұрын
You are just awesome !!.. Cant believe i wrote the code myself after listening to this video !!
@Ramanujan-c5c2 ай бұрын
Beautiful code .... creative way to solve it. Loved it. I heard that u are quite good coder, its true. U deserve the fame as striver... launch few short videos here and on linkedin. Hope u reach to great heights. I am really thankful to u for sharing so many great codes and solving problems with so ease. Love ur solution. Thank u so much for helping newbie coders and turning them towards Guardian of Ltc and red coder of CFr. Keep shining Sir. Tc.
@codestorywithMIK2 ай бұрын
This means a lot. Thank you ❤️❤️❤️
@nik38893 ай бұрын
how ! i never seen that type of solution that is the best solution i ever watched
@souravjoshi2293 Жыл бұрын
I think you are the best who can make things easier like a cake walk
@akshaychavan55116 ай бұрын
This question felt hard for me when I initially attempted it. But, now it feels quite easy.
@atifhu Жыл бұрын
Bhai kya smjhate ho❤️❤️
@gui-codes6 ай бұрын
too good man. becoming your fan day by day. One stop for revision
@vineetkumar2899 Жыл бұрын
awesome bhaiya😍
@mayankagarwal67752 ай бұрын
really really good explanation. thanks for your efforts😃
@ShivaaySingh207 ай бұрын
Thank you so much bhai for making this question very easy to understand 🙌❤.
@tutuimam3381 Жыл бұрын
Amazing explanation🌹
@elakstein Жыл бұрын
Good one. Just want to point out that currently the time complexity is O(NlogK) and space complexity is O(logK) because of recursion stack, it can be solved iteratively with the same time complexity but with O(1) space complexity.
@codestorywithMIK Жыл бұрын
Indeed
@alphadrones23 Жыл бұрын
yup.. we could use the iterative approach to merge the two lists
@zgodgaming8579 ай бұрын
the best explanation
@khushijain3574 Жыл бұрын
you explained so nicely keep making such videos
@codestorywithMIK Жыл бұрын
Thank you so much 😇🙏
@khushijain3574 Жыл бұрын
@@codestorywithMIK please create video on quick sort on linked list , i want your approach to solve this thanks
very good explanation pls make video on today leetcode contest questions
@codestorywithMIK Жыл бұрын
I will soon start those as well . Just trying to make plans as per my time management. Soon
@priyanshudubey2245 Жыл бұрын
Bhaiya weekly contests ke questions par bhi video bana dijiye please.
@codestorywithMIK Жыл бұрын
I will soon start those as well . Just trying to make plans as per my time management. Soon
@RohitYadav-uo6uo Жыл бұрын
can't we use a for loop in which we merge first two then we will merge the answer of that to next list and like that isn't that a good way?
@saisathvikreddyloka7578 Жыл бұрын
🔥🔥
@ishwarkokkili7646 Жыл бұрын
Masterful !!
@codestorywithMIK Жыл бұрын
Thank you so much 🙏❤️😇
@shivamjadon2257 Жыл бұрын
mast video
@codestorywithMIK Жыл бұрын
Thank you 😇🙏
@sunshineandrainbow54534 ай бұрын
What is the need of partition and merge, we can simply use a for loop from i =2 to n-1 and merge the result of lists[0] & lists[1] with lists[i] . At each iteration mergedList = merge(lists[i],mergedList) ...
@mindpower1854 ай бұрын
@codestorywithMIK ek baar just Merge K sorted array wala ...explain kardo ya github pe upload kardo please
@harshlakra32609 ай бұрын
concepts ki video kab aarhi h
@surajsidar32805 ай бұрын
If I submit Python code then There is TLE error if we submit using an iterative approach There is a maximum recursive depth error if I follow the recursive approach.
@vishalgautam-f6v Жыл бұрын
what will be the recurrence relation for the given algorithm? If it is T(k) = 2*T(k/2)+n then it will result in n*k or if it is not the correct recurrence relation then what will be the correct relation?
@ShivaaySingh207 ай бұрын
interview me yadi questions puche to mai bhi interviewer se kahunga "Aao Story Se Code Kre "😁😅
@codestorywithMIK7 ай бұрын
Cool 😅❤️
@nik38893 ай бұрын
bhai ek bar k sorted array wala kra do
@MakeuPerfect Жыл бұрын
bhaiya minimum height trees wala question karao plz
@codestorywithMIK Жыл бұрын
Can you please share leetocde link
@MakeuPerfect Жыл бұрын
@@codestorywithMIK meine link diya tha bhej diya but ye dikhai nahi de raha comment mein
Bhaiya, i thought of this on the first go ListNode* mergeTwoLists(ListNode* list1, ListNode* list2){ ListNode* head = NULL; ListNode* tail = NULL; if(list1==NULL) return list2; if(list2==NULL) return list1; if(list1->val < list2->val){ head = list1; list1 = list1->next; } else{ head = list2; list2 = list2->next; } tail = head; while(list1 && list2){ if(list1->val < list2->val){ tail->next = list1; list1 = list1->next; } else{ tail->next = list2; list2=list2->next; } tail=tail->next; } if(!list1) tail->next=list2; else tail->next=list1; return head; } ListNode* mergeKLists(vector& lists) { int k = lists.size(); if(k == 0){ return NULL; } if(k == 1){ return lists[0]; } ListNode* res = mergeTwoLists(lists[0], lists[1]); for(int i = 2 ; i < k ; i++){ res = mergeTwoLists(res, lists[i]); } return res; } Ye bhi sahi hai na?
@codestorywithMIK Жыл бұрын
Yes it should work too.
@harsh.jain22 Жыл бұрын
I also thought of the exact same solution of iteration in first go 🤜🤛
@yashsharma177410 ай бұрын
Your time complexity calculation is incorrect. It will be O(k*n). This is because you have perform calculation at each leaf here but in case of binary search you do calculation at each node of traversed path.
@Whirlwind03 Жыл бұрын
Beautiful solution brother, I solved it using PriorityQueue now will solve using your approach public class Pair implements Comparable { ListNode node; public Pair(ListNode node){ this.node = node; } @Override public int compareTo(Pair o){ return this.node.val - o.node.val; } } public ListNode mergeKLists(ListNode[] lists) { if(lists.length == 0) return null; ListNode res = new ListNode(-1); ListNode t = res; PriorityQueue pq = new PriorityQueue(); for(int i=0;i 0){ Pair rem = pq.remove(); t.next = rem.node; t = t.next; if(rem.node.next != null){ pq.add(new Pair(rem.node.next)); } } return res.next; }