Join this telegram channel for regular updates : t.me/alGOdsRUclips Join this telegram channel for doubts and discussions : t.me/joinchat/PqjeMhz0MBR-tg31OK2Dsg
very nice explaination i am struggling with this quetion since a week but we can also use upperbound function to calculate the number of elements which are smaller than k by iterating over rows
Thank you for the video. Just some minor comment: When discussing complexity, I'd always simplify the classes just to avoid confusion when you are comparing different algorithms with similar complexities. For example, at 2:06, I'd rather say O(n^2 log n).
Hey! how will this solution handle the case when suppose mid is 4 (4 isn't in the matrix) and number of elements less than 4 comes out to be required then we have to decrease the high bound, but what if answer was actually 5 (which was actually present in the matrix) but we will never check for 5.
In that case, we won't change the low variable but assign mid-value to the high and we go for another iteration to check the same count is occurring or not if it does then the previous count value is not the correct one!
Educative.io course grokking the coding the interview is the source or go to the Leetcode discuss there you will get nicer explanation of this question
he copied it from leetcode. if he did not copy he would explained the so called "intuition", but no, he jumps straight into algorithm which is a clear indication that he didn't come up with this on his own.
At 2:10 why do we need to sort the array? why can't we just iterate the matrix with two loops and print the value at k-1. This will give us O(n^2) complexity right?
Maybe the matrix will have 1 2 3 4 5 8 7 8 9 See the 7 will come after 8 in your soluitino (the last element of previous row might no be bigger than first element of next row:D
int solve(int mat[][c], int r, int c, int k){ int min = mat[0][0], max = mat[c-1][c-1]; int desired = k; while(min < max){ int mid = min+(max-min)/2; int place = 0; for(int i=0; i
Doesn't work for the following matrix 1 4 7 2 5 8 3 6 9 Now for 4th element using your formula we get, a[(4-1)/3][(4-1)%3] = a[1][0] = 2. Which is obviously not the correct answer.
@@satishmhetre5301 sorted matrix means 123 456 789.. otherwise the author would not have mentioned first method to push them in array and choose arr[k-1] out of that
Join this telegram channel for regular updates : t.me/alGOdsRUclips
Join this telegram channel for doubts and discussions : t.me/joinchat/PqjeMhz0MBR-tg31OK2Dsg
I didn't get it. It is too difficult to get for a beginner. Please explain its code if possible.
very nice explaination i am struggling with this quetion since a week but we can also use upperbound function to calculate the number of elements which are smaller than k by iterating over rows
Thank you for the video. Just some minor comment: When discussing complexity, I'd always simplify the classes just to avoid confusion when you are comparing different algorithms with similar complexities. For example, at 2:06, I'd rather say O(n^2 log n).
Hey! how will this solution handle the case when suppose mid is 4 (4 isn't in the matrix) and number of elements less than 4 comes out to be required then we have to decrease the high bound, but what if answer was actually 5 (which was actually present in the matrix) but we will never check for 5.
Same Doubt
In that case, we won't change the low variable but assign mid-value to the high and we go for another iteration to check the same count is occurring or not if it does then the previous count value is not the correct one!
you can go to this link for a better explanation ruclips.net/video/dpsp1hP6P-U/видео.html
Thanks bro for this intuition. Saved me a lot of time.
(low+high)/2 is subject to overflow. Use low + (high-low)/2 OR high - (high-low)/2
bro from where did you learn this algorithm?
This algorithm is a mixture of two algos.
There's no exact source available to learn this algorithm.
It comes from practice and intuition :)
Educative.io course grokking the coding the interview is the source or go to the Leetcode discuss there you will get nicer explanation of this question
ruclips.net/video/oeQlc87HbbQ/видео.html
he copied it from leetcode. if he did not copy he would explained the so called "intuition", but no, he jumps straight into algorithm which is a clear indication that he didn't come up with this on his own.
At 2:10 why do we need to sort the array? why can't we just iterate the matrix with two loops and print the value at k-1. This will give us O(n^2) complexity right?
Maybe the matrix will have
1 2 3
4 5 8
7 8 9
See the 7 will come after 8 in your soluitino (the last element of previous row might no be bigger than first element of next row:D
int solve(int mat[][c], int r, int c, int k){
int min = mat[0][0], max = mat[c-1][c-1];
int desired = k;
while(min < max){
int mid = min+(max-min)/2;
int place = 0;
for(int i=0; i
Plz solve using heaps as well..
Why during dry run you applying binary search on the elements instead of the index of the elements, is there any specific reason?
Hi, Can you explain this(08:45) a bit more, please?
good for nothing,why you cannot simply return a[(k-1)/c][(k-1)%c]
Doesn't work for the following matrix
1 4 7
2 5 8
3 6 9
Now for 4th element using your formula we get, a[(4-1)/3][(4-1)%3] = a[1][0] = 2. Which is obviously not the correct answer.
@@satishmhetre5301 sorted matrix means 123 456 789.. otherwise the author would not have mentioned first method to push them in array and choose arr[k-1] out of that
Matrix given by me is row wise sorted.
@@satishmhetre7117 then this approach won't work
Omg, You made it so simple... I was stuck with this for 3 days, solved it in 10 mins
Count function explanation is not good plzz give more details about it.
you are really god of algos keep continuing this good work
Need of count ??
Wonderful explanation!
Excellent 👌
Keep it up. Going very well👍👍
Thank You!!😁😄
Veryyyy well explained ✨🔥
Thank You😁😇
didnt understand
this tutorial was not helpful at all, please give a better explanation from next time.
Thanks
Glad to help:)
Awesome explanation!
Glad you liked it :)
Your approach is a bit wrong.
It was difficult to understand but great work 😃
Mere se bhi dislike le le bhai
Very bad explanation although this solution is a good one...