Regarding editorial solution provided

in editorial solution for this question there is a loop for row
but i don’ think that is required.
check this code.

#include
using namespace std;

void matrix_search(int **a,int m,int n,int key){
int row=0;
for(int col=n-1;col>=0 && row<m;){
if(a[row][col]==key){
cout<<“1”;
return;
}
if(a[row][col]>key){
col–;
}else{
row++;
}
}
cout<<“0”;
}

int main() {
int m,n;
cin>>m>>n;
int *a=new int[m];
for(int i=0;i<n;i++){
a[i]=new int [n];
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}
int key;
cin>>key;
matrix_search(a,m,n,key);
return 0;
}

Yes your approach is correct. The problem is same as the staircase search whose lecture video must be there in your playlist.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.