I wrote this solution before watching your explanation, and It works perfectly fine. class Solution { public boolean searchMatrix(int[][] matrix, int target) { int m = matrix.length; int n = matrix[0].length; int top = 0; int bottom = m-1; while(top < bottom){ int mid = top + (bottom-top)/2; if(matrix[mid][n-1] == target){ return true; } else if(matrix[mid][n-1] > target){ bottom = mid; } else{ top = mid+1; } } int l = 0; int r = n-1; while(l target){ r = mid-1; } else{ l = mid+1; } } return false; } }
public boolean searchMatrix(int[][] arr, int target) { int i = 0; int j = arr[0].length - 1; while (i < arr.length && j >= 0) { if (target > arr[i][j]) { i++; }else if (target < arr[i][j]) { j--; } else { return true; } } return false; } // sample solution of brute force
nice explained bhaiya
apka video dekhne ke baad koi aur doubt hi nahi rehta ❤❤thnx bhaiya
aur bsearch ka question karaoge na ?
Thanks a lot ❤️❤️
Yes, i will post more on bsearch soon
I had done this problem before lkn yaar aapka solution.. ufff itta easy nd clean❤❤
Best. As usual⚡.
u made this question so simple ..........thanks from the bottom of my heart ❤❤
Just searched for your solution on UA-cam and got it. As always the best explanation
best exaplantion sir , single matrix se kafi easay hoagya samjhna
I am glad it helped ❤️❤️❤️
nice and great explanation sir
you are the best tutor on internet. I wonder what it would be like having a teacher like him in our colleges
college can't afford MIK
I have solved before you showing code. and leaned binary search from your previous video. Thank you sir.
Thank you so much 😇❤️
Best explanation ever 😊👏
Crystal clear as always. You are just dope
super
Wonderful explanation
Best explanation ever ❤❤❤
GREAT !!💙
great explanation bro
Super easy explanation
Thank you 😇❤️
Nice bhaiya
thanks bhaiya you are really great
Thanks a lot ❤️❤️
you made it super easiest
Awesome!
Thank you so much 😇❤️
maine pehle m*log(n) ka solution nikala tha...but I learnt something new
Thankyou Sir!
understood
Why we take in matrix[0] in n??
Bro just do dry run with different matrix you got your answer ❤
I wrote this solution before watching your explanation, and It works perfectly fine.
class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
int m = matrix.length;
int n = matrix[0].length;
int top = 0;
int bottom = m-1;
while(top < bottom){
int mid = top + (bottom-top)/2;
if(matrix[mid][n-1] == target){
return true;
}
else if(matrix[mid][n-1] > target){
bottom = mid;
}
else{
top = mid+1;
}
}
int l = 0;
int r = n-1;
while(l target){
r = mid-1;
}
else{
l = mid+1;
}
}
return false;
}
}
why divide by n not m? mid/n and mid%n
class Solution {
public:
bool searchMatrix(vector& matrix, int target) {
int m = matrix.size();
int n = matrix[0].size();
int start=0;
int end=m*n-1;
while(start target){
end = mid-1;
}
else if(element < target){
start = mid+1;
}
else {
return true;
}
}
return false;
}
};
@codestorywithmik bhai Mai to bhool gya hu tumhare siwa koi or bhi coding sikhata hai youtube pe❤
Means a lot 😇❤️
i guess there will be a small correction that the first taught approach will have a time complexity of O(n+m) not O(n^2)
please solve meeting rooms 2 leetcode premium question
public boolean searchMatrix(int[][] arr, int target) {
int i = 0;
int j = arr[0].length - 1;
while (i < arr.length && j >= 0) {
if (target > arr[i][j]) {
i++;
}else if (target < arr[i][j]) {
j--;
} else {
return true;
}
}
return false;
} // sample solution of brute force
You made it super duper easy 🫡🫡