Row with max 1's | Naive-Better-Best Approach | Matrix | Interview Question
Vložit
- čas přidán 14. 11. 2020
- In this video I have explained the solution for row with max 1's starting from Naive to Optimal Approach.
DO LIKE AND SHARE THIS VIDEO AND DON'T FORGET TO SUBSCRIBE !!
C++:- github.com/tejasbirsingh/Prog...
nicely explained
Great Explanation 👏
superb
wonderful presentation
Great explanation. Thanks brother
Awesome explanation👌👌
Great explanation
thanks buddy good explanation keep making videos
Thanks!
I also thought the same naive approach(except i initialized row=-1), i thought it will show tle but it failed in one of the cases.
Thanks brother
Bro do subscribe to support. Thanks!
hello bro we have to return the first instance of max 1's the code you wrote shows the latest instance of the code, please help me with that
at 13:41 , for column if worst case is that all rows have 0 and only one column and one row has 1 (bottom right and bottom left)
then you traverse each row and column , so it is also o(N*M) right?
What if 1st row has all 0 with no 1...then your code must b wrong
Exactly..
But I think binary search on everyrow works it takes less tiem
When I m submitting my code it is showing your code failed for multiple testcases. please help
Can you share your code?
Bro optimal 1 solution is giving wrong answer in one case where N=1000 and M=1000 , It's correct ouput is 976 but code is giving 0 answer. Don't know why ?
how O(n+m) is best approach ???
best will be O(log(m))
Using Binary search will be O(Logn) which will be applied on each row therefore total time will be O(totalRows Log (totalCols)) whereas Pointers approach will take O(n + m ) time which is less than n log m.
@@ClashingCoder
int rowWithMax1s(vector a, int n, int m)
{
int res=-1;
for(int i=0;i
your explanation is good but try to reduce the pace.
Yea I have got feedback from many viewers on that. In new video I will improve that. Thanks!
Can you explain why the TC of optimal solution is O(N + M)
because you travelling m horizontal steps and n vertical steps to traverse the complete array in worst case therefore O(n+m)
bro what will be the answer for test case 3 3 -----> 0 1 1 1 0 0 0 0 0
This will not be a valid input this question as in a row there can't be 0s after 1. For the input provided by you this algorithm will output 1 as answer as per 0 based indexing. So this answer will be wrong in sense of maximum 1's per row
Confusing, sorry but it' is truth.
I will try to improve video quality and explain properly. Thanks for pointing out the problem!
Most Simple Solution based on the logic
int row=m;
int pos=-1;
for (int i=0;i