diff --git a/GFG/search_2dmatrix.cpp b/GFG/search_2dmatrix.cpp new file mode 100644 index 0000000..96fe9a7 --- /dev/null +++ b/GFG/search_2dmatrix.cpp @@ -0,0 +1,52 @@ +// Question link - https://practice.geeksforgeeks.org/problems/search-in-a-matrix17201720/1 + +#include +using namespace std; + + + // } Driver Code Ends +//User function template for C++ +class Solution{ +public: + int matSearch (vector > &mat, int N, int M, int X) + { + int i=0,j=M-1; + while(i=0) + { + if(mat[i][j]==X) + return 1; + else if(mat[i][j]>X){ + if(j>0) + j--; + else + return 0; + } + else{ + if(i> t; + while (t--){ + int n, m; cin >> n >> m; + vector > arr (n, vector (m)); + for (int i=0;i> arr[i][j]; + + int x; cin >> x; + Solution ob; + cout << ob.matSearch (arr, n, m, x) << endl; + } +} // } Driver Code Ends \ No newline at end of file