Staircase code problem

please send me the code I only just want to match with my code

hey @tarshid7 check this

#include<iostream>
using namespace std;
int main(){
	int m,n;
	cin>>m>>n;
	int a[100][100];
    for(int i=0;i<m;i++){
    	for(int j=0;j<n;j++){
    		cin>>a[i][j];
		}
	}
	int key;
	cin>>key;
	int i=0;
	int j=n-1;
	while(i<=m-1 && j>=0){
		if(key>a[i][j]){
			i++;
		}
		else if(key<a[i][j]){
			j--;
		}
		else{
			cout<<i<<endl;
			cout<<j<<endl;
            break;
		}
	}
	return 0;
}

basically at last we just need to give the address index like we did in binary and linear that’s it

Yes @tarshid7 this is the only missing issue in your code.

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.

it will only implement in sorted 2 d array or when we have unsorted 2 d array how we will do that one can you pelease tell me that how to sort. a 2d array just write like sort(a[row],a[row]+n); like we do in linear array or something diff is there

reply me fast please

refer this --> https://ide.codingblocks.com/s/624212

I am not asking this I had did it before I was just asking that this search can be applied only in sorted 2 d array and if we get unsorted than what we will do what about that I am asking

rest all are same like binary only here we do not have to find mid index rest oll the process is same

this approach is valid only in sorted array… else u can simply run 2 loops and find in o(n^2)… or sort the array across each row and col and then apply this method…

so for sorting each row we can write like sort(a[row],a[row]+n); like this

yes. correct…
i hope it clears all ur doubts

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.