Row of Matrix with Maximum Number of 1s | GFG | Hindi | Problem Solving | FAANG | Shashwat
Vložit
- čas přidán 3. 08. 2021
- Java Plus DSA Complete Placement Course:
• Java and DSA Course Pl...
Problem Statement:
Given a boolean 2D array of n x m dimensions where each row is sorted. Find the 0-based index of the first row that has the maximum number of 1's.
Problem Link:
practice.geeksforgeeks.org/pr...
Solution Snippet:
github.com/Tiwarishashwat/Int...
Company Tags:
Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe
Instagram Handle: (@shashwat_tiwari_st)
shashwattiwari.page.link/shas...
#ShashwatTiwari #coding #problemsolving #leetcode #hackerrank #hackerearth #codechef #codesignal #algorithms #javaprogramming #sde #placement #programming
This is a very old video, for better sound and camera quality DSA videos, learn from the below playlist!
Java Plus DSA ( Java + DSA + Problem Solving )
czcams.com/play/PLQ7ZAf76c0ZPVdhV1bAjFv0bQc1xHURzE.html
nice explain sir
great explanation. Thanks a lot sir.
Note: Time complexity for the 2nd solution will be O(n+m), it's not log(n+m).
same doubt
awesome explanation sir..!!
Really great explanation..Thanks sir
Optimal approach 10:44
very well explained sir , thanks a lot
grear explaination sir
Very well explained. Keep up the great work. I would love to see the videos more if the videos and voice are more clear. All the best brother.!
Thanks for the feedback. Will work on it!
Please solve this by binary search also
It will be out next week in java plus dsa course...
Great
I have another optimal approach in mind. Idk if it works or not. We start from the left side and as soon as we find 1, that is our max row. If we don't find any 1s in the entire first column, go to 2nd column (from left)
Looks okay, to me. I think it should work. Great!
@@shashwat_tiwari_st No, in this approach time complexity is O(m*n)
You are still trying to traverse all the elements in the matrix, assume there are no 1s in the matrix. That's the worst case.
Bro this one soo goodd…it really worked in the first attempt on gfg❤️ even with the constraints of time complexity be O(n+m).
Is this O(n+m) ?
class Solution:
def rowWithMax1s(self,arr, n, m):
ansRow = -1
for i in range(n):
for j in range(m):
if arr[i][j] == 1 and j < m:
m = j
ansRow = i
break
return ansRow
Bro Your explanation is good. but take some time to explain code , you are too hurry it will difficult for beginners you are explaining code in last 1min in hurry , btw best explanation buddy keepitup:)
Sure.
bhaiya Nice explanation, Binary search ke code ka bhi video bana do
Sure :)
bhaiya binary search waali code ki video banado
when I am submitting this. gfg saying " Time limit exceeded "
Yes I checked just now. There is some error on GFG IDE, because none of the solution is working even not the ones given in editorials.
@@shashwat_tiwari_st yeah i tried others too
If matrix is unsorted ?
why column is initialize with m-1
Total columns are m.
Last index will be m-1.
Same like array if Total elements are 10.
Index will be 0,1,2....,9 so last is 9. Same logic in matrix also. You can check java dsa course. There I have taught all of this...
@@shashwat_tiwari_st thank you, your explanation is very good
time c is : o(n+m) ? you said o(log(n+m))
yes, I did not notice it, I said log by mistake, it should be O(n+m).
Thanks for letting me know.
@@shashwat_tiwari_st thanks for explained well.
bhai agar loop ke inside loop hota h to time complexity n* n hoti fir isme O(n+ m ) kse?
@@GhostRider.... because here we are not traversing all the elements present inside the matrix.