The logic is correct but the first test case is not getting passed
First test case not getting passed
#include using namespace std; int main() { long long int n,m,a[100][100]; cin>>n>>m; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { cin>>a[i][j]; } } long long int key; cin>>key; int i=0,j=n-1; long long int sea=a[i][j]; if(sea==key) { cout<<ā1ā; return 0; } while(i<=n-1 && j>=0) { if(a[i][j]>key) { jā; } else if(a[i][j]<key) { i++; } else if(a[i][j]==key) { cout<<1<<endl; return 0; } } cout<<0; return 0; }
Hello @tusharnitharwal,
You have done a silly mistake in your code.
The initial value for j is wrong.
I have corrected your code:
Hope, this would help.
Give a like if you are satisfied.
thanks a lot for the help