Merge k Sorted Lists - (Leetcode - 23) - (Google, Amazon, Microsoft..) : Explanation ➕ Live Coding

preview_player
Показать описание
This is the 8th Video on our Linked List Playlist.
In this video we will try to solve another interesting and very popular Linked List problem "Merge k Sorted Lists" (Leetcode-23).
Although it's marked hard, this will be so much easier to understand.

Problem Name : Merge k Sorted Lists
Company Tags : VMWare, Amazon, Uber, Google, Twitter, LinkedIn, Airbnb, Facebook, Microsoft, IXL

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish
Рекомендации по теме
Комментарии
Автор

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) {
l1.next = mergeTwoSortedList(l1.next, l2);
return l1;
}

else 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);
}
}

JJ-tpdd
Автор

15 min ke baad khud se, code likh ke submit and got accepted the way he explain 🙏🙏😻😻

GghiggFfhhhf
Автор

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.

itsaayush
Автор

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)

guptajiivlogging
Автор

You are just awesome !!.. Cant believe i wrote the code myself after listening to this video !!

shweta
Автор

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.

Ramanujan-cc
Автор

how ! i never seen that type of solution that is the best solution i ever watched

nik
Автор

I think you are the best who can make things easier like a cake walk

souravjoshi
Автор

This question felt hard for me when I initially attempted it. But, now it feels quite easy.

akshaychavan
Автор

too good man. becoming your fan day by day. One stop for revision

gui-codes
Автор

really really good explanation.
thanks for your efforts😃

mayankagarwal
Автор

Thank you so much bhai for making this question very easy to understand 🙌❤.

ShivaaySingh
Автор

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.

elakstein
Автор

you explained so nicely keep making such videos

khushijain
Автор

Thank You soo much sir !!
You really made it easy

nihalsingh
Автор

Merge two sorted List -- Leetcode 21


class Solution {

private ListNode mergeTwoSortedList(ListNode l1, ListNode l2) {

if(l1 == null) return l2;
if(l2 == null) return l1;

if(l1.val <= l2.val) {
l1.next = mergeTwoSortedList(l1.next, l2);
return l1;
}

else if(l1.val > l2.val) {
l2.next = mergeTwoSortedList(l1, l2.next);
return l2;
}
return null;
}


public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
return mergeTwoSortedList(list1, list2);
}
}

JJ-tpdd
Автор

very good explanation
pls make video on today leetcode contest questions

U-nw
Автор

Bhaiya weekly contests ke questions par bhi video bana dijiye please.

priyanshudubey
Автор

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?

RohitYadav-uouo
Автор

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) ...

sunshineandrainbow
welcome to shbcf.ru