Row With Maximum 1s | Arrays | 2-D Array | GeeksForGeeks | LeetCode | Explanation by alGOds!!!
Vložit
- čas přidán 7. 09. 2024
- In this video, Vishesh Aggarwal has explained the optimized approach for solving the question #RowWithMax1s from #GeeksForGeeks and is asked in #Google #Amazon #Microsoft #FAANG
Question Link - practice.geeks...
Solution for Reference - ide.geeksforge...
Feel free to ask any of your doubts and discuss your attempts related to this question in the comments section 😇.
Join this telegram channel for regular updates : t.me/alGOdsYou...
Join this telegram channel for doubts and discussions : t.me/joinchat/...
Do like and subscribe to our channel and click the bell icon so you don’t miss any future videos!!.
Don’t forget to tell us about the Questions you need an explanatory video for in the comments section. We’ll definitely take care of it😁.
Here is the Subscription Link : / algods99
Connect with us on Gmail : algods.99@gmail.com
The contributors to this channel and their profile links are enlisted below
1) Vishesh Aggarwal:
LinkedIn :- / vishesh-aggarwal-830b5...
2) Vaibhav Varshney:
LinkedIn :- / vaibhav-varshney
3) Vagish Yagnik:
LinkedIn :- / vagish-yagnik-9203b0172
4) Vishesh Jain:
LinkedIn :- / vishesh-jain-138097174
5) Achint Dawra:
LinkedIn :- / achint-dawra-ba9550168
6) V Sriram:
LinkedIn :- / sriram-v-08b098170
7) Varun Bajlotra:
LinkedIn :- / varun-bajlotra-17715a170
8) Vikas Yadav:
LinkedIn :- / vikas-yadav-b432b5107
Join this telegram channel for regular updates : t.me/alGOdsCZcams
Join this telegram channel for doubts and discussions : t.me/joinchat/PqjeMhz0MBR-tg31OK2Dsg
we can also do one thing just iterate cloumn wise when the very first 1 come then return its row number
for(int j=0;j
Nice buddy
take the case where all the rows but one have all the elements as 0
example {0000,0000,0000,0000,0000,0000,0000,0000,0001}, here when your logic is applied the time complexity will turn out to be O(N*M), nice solution though :)
@@vishwan7280 you can't optimise this case 😂 , so this is the best solution I guess , or some bitmagic may do fine
o(m*n)
@@vishwan7280 you can use the logic mentioned in the video which must be optimal since you can eliminate the all the rows once you encounter 0.but int his case 0111,0111,0111,1111 the time complexity is near about O(m*n)
thank you for the good explanation
one subscriber is increased😁😄
keep uploading a video like this 🤞👍
And what of we don't get any one 1 in first row??
Then do we need to search in next row..until we don't get the row with 1??
bhari explanation 🤩🤩mast
thanks for such a wonderful explaination
Nice explanation. Thanks a lot.
thankss for tthis wonderful explaination brother!
wonderful solution!!
Python code:
def rowWithMax1s(matrix: [[int]], n: int, m: int) -> int:
if matrix[0][0] == 1:
return 0
rowCount = 0
count = 0
row = -1
r = 0
c = m - 1
while r < n and c >= 0:
if matrix[r][c] == 1:
count = m - c
c -= 1
if count > rowCount:
row = r
rowCount = count
else:
r += 1
return row
But the expected time complexity is O(N+M)
the code in the description fails at test case 2 1
00
00
extra condition if(j==m-1)
return -1;
Thanks man!
binary search method won't work because Binary search does not return the index of the first occurrence of 1
I think you can modify the binary search to find the first and last occurrence of any target element
Great Explanation
Subscriber++;
you havent written any code too , so how will you say that your algorithm works?
how will you make the binary search , search the first one? at 2:42 ?
for the first one also linear search is used I guess but from last index that is (m-1)
Thanks brother!
Nice video
Best 👌🏼👌🏼👌🏼
Thanks!!
Do share our channel among your friends and college mates if you found our content useful😊
what if the matrix is
00
00
aur waise bhi ye m*n ki tym complexity hai
After second for loop put this condition
if(j==m-1)
return -1;
bhai code klha hai ??
disappointed u should have included code
can anyone send me the code in python for last approach which he have mention in the video
can you do it in python
shit this was so simple poor me !
the same bro,🤣🤣🤣 I did not notice that sorted row is given😶
In the last approach,
for a test case where all elements in 2D matrix is 0 , How can be the complexity is (n+m)
{
0,0,0,0,0
0,0,0,0,0
0,0,0,0,0
0,0,0,0,0
0,0,0,0,0
}
he is talking about worst complexity.
bro if all elements are 0 then it's t.c will become o(n) only not even o(n+m) because it checks all row's last element ino(n) and outer row check loop will ends and it just returns without checking haha so simple
bhai leetcode me implement kr deta
explanation is best.......but plz share code with it ,,,, without code it is useless.............
Hi Rishabh! We always provide the solution link in the description. You can check it there :)
Where is the code I couldn't find it please share
Check the description : )
Hey kindly upload more vedios for competitive coding .
I m finding difficulty in maximum profit in selling share twice problem. So if you could help me with this.
your intro is cringy as f... ur good in explaination