The K Weakest Rows in a Matrix | 2 Approaches | Binary Search | Heap | Sorting | Leetcode - 1337

preview_player
Показать описание
This is the 57th Video on our Arrays (1-D & 2-D) Playlist.
In this video we will try to solve a very famous 2-D Array+Binary Search Problem - The K Weakest Rows in a Matrix (Leetcode-1337).

I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.

Problem Name : The K Weakest Rows in a Matrix
Company Tags : AMAZON

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

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

I solved this question by my own using set. Still I came here to know MIK approaches, you're an absolute gem!

manaskhare
Автор

very in depth explanation and thanks for explaining when to use min-heap and max-heap as this is asked by alot of folks in the comment.

floatingpoint
Автор

MIK bhai ek hi dil kitni bar jitoge... best explanation bhai as always....😍😍😍😍

youcantgetme
Автор

Great handwriting, good voice quality, and clear explanations

sandeepankalita
Автор

Hi sir, i have done this using binary search in the process of finding smallest element .
its only because of you love u sir.

csechandrasekhar
Автор

Loved the explanation. Clean and simple as always

FanIQQuiz
Автор

Yes yes
Even i was going to comment of 2 videos per day
But saw ur reply of out of india


Bro plzz in future 2 videos per day.

And also one video dedicated for how to be consistent
Motivation related please

BenJasper-ux
Автор

Your videos are superb, My placement is near and covering all videos of all playlists is a long process, can you please make a of very imp. and frequently asked questions? Also it would be very great if for each question in the sheet we have a link to your video.
I know there are lots of sheets available but, I only trust you, please consider this request, it will help a lot to all students.

harsh.jain
Автор

did the question on my own, just had one doubt, Can't we use the count function to find the number of 1's instead of the binarySearch function?
the second explanation was 🔥

Shin_Ry
Автор

What the explanation sir Hats off!!!!
One Request From Community : Can you also try to make solution video for the Weekly and Biweekly contest after the contest. Atleast 3, 4 question??

avishkargaikwad
Автор

Clean Python Code: Heap

class Solution:
def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]:

min_heap = []
ans = []

for i in range(len(mat)):
heapq.heappush(min_heap, (sum(mat[i]), i))

for _ in range(k):
sum_, idx = heapq.heappop(min_heap)
ans.append(idx)

return ans

ishwarkoki
Автор

bhaiya tumhari coding skills kafi jyaada achhi h

Abhay
Автор

Sir yesterday i was asking about sde sheet

Tejaswi-xdre
Автор

Sir OA ni nikalte h
usme ek video banaiye please

sagargupta
Автор

really well explained video sir than
k you...sir please check linkdin whenever you get time

percyx
Автор

BF APPROACH.
Class solution {
public int []k Weakest Row(int [][]mat, int k){
int[][]cnt =new int [mat.length][2];
for (int i=0;i<mat.length;i++){
int sum =0;
for(j:mat[i]){
sum+=j;
}
cnt [i][0]=sum;
cnt [i][1]=i;
Array. Sort(cnt, (a, b)-->a[0]==b[0]?a[1]-b[1]:a[0]-b[0]);
int []res =new int [k];
for(int i=0;i<k;i++){
res[i]=cnt [i][1];
}
return res;
}
};
2nd approach.
class solution {
public int []k Weakest Row (int [][]mat, int k){
Tree set<int []>set=new Tree set<>(new compare<int []>(){
@override
public int compare(int []a, int []b){
if(a[0]!=b[0])
return interger compare (a[0], b[0])
else
return interger compare (a[1], b[1])
}
});
for(int row =0;row <mat.length;row ++){
int cnt =binary search (mat[row]);
set.add (new int []{cnt, row});
}
int[]res=new int [k];
iterater <int []>iterater=set.iterater();
for(int i=0;i<k;i++){
res[i]=iterater.next()[i];
}
return res;
}
Private int binary search (int []row){
int low =0;high =row-1;
while (low <=high){
int mid =(low +high)/2;
if(row [mid]==1)
low =mid +1;
else
high =mid-1;
}
return low;
}
};
Thanks for 9k+subscription;🎉❤😮

dayashankarlakhotia
Автор

sorting algo stable hona chahiye according requirement.

rahiljakir
Автор

Bhaiya, would it be possible to put 2 videos per day.

CodingJoySoul
Автор

Bhaiya aapne motivation add karna bnd
kardiya

AbhishekGupta-ejvw
join shbcf.ru