Matrix Search(all test case not cleared)
Hey Shubham, you are supposed to print “0” if you didn’t find the element in the matrix but you are printing “o” , and your approach is also not correct you are supposed to use one nested loop also, outer loop will be for row and inner loop for column.
your approach is also not correct you are supposed to use one nested loop also, outer loop will be for row and inner loop for column.
I didn’t get this?
Hey Shubham, here I am sharing the code snippet for it you can refer this
void matrixSearch(int **arr, int n , int m, int key) {
for(int row = 0;row < n;) {
for(int col=m-1;col>=0 and row < n;) {
if(arr[row][col] == key) {
cout<<1;
return;
} else if(arr[row][col] > key) {
col--;
} else {
row++;
}
}
}
cout<<0;
return ;
}