Java Solution with Explaination - Faster than 100%
Two condition provided is \n1. rows are sorted in ascending order\n2. cols are sorted in ascending order\n\n  We first start with first row and last column elem
Two condition provided is \n1. rows are sorted in ascending order\n2. cols are sorted in ascending order\n\n*  We first start with first row and last column element in 2D matrix.\n*  Idea here is we maintain two pointer\'s.\n    i) for row\n   ii) for col\njust like any 2D matrix problems\n\n* now we compare current Element pointed by rowIndex and colIndex with target, if it matches then return true.\n* if it does not match then, two possibility, we can go down(rowIndex++) or go left(colIndex--)\n* we compare if current Element is smaller than the target\n   i) if it\'s smaller, then we go down as all the elemnts on the left side of the current element is smaller(rows in ascending order).\nii) if not, then we go left, as our solution doesnot lie in current column(because col is sorted in ascending, so all the elements below in current col are greater than current element.)\n\nTime Complexity:\nassuming, \nnum of rows = m\nnum of cols = n\n\ncomplexity : O(m+n)\n\nSpace complexity: O(1)\n\n```\nclass Solution {\n    public boolean searchMatrix(int[][] matrix, int target) {\n        if (matrix.length == 0) return false;\n       \n        int rowIndex = 0;\n        int colIndex = matrix[0].length - 1;\n        \n        while(rowIndex < matrix.length && colIndex >= 0) {\n            if (matrix[rowIndex][colIndex] == target)\n                return true;\n            \n            if(matrix[rowIndex][colIndex] < target)\n                rowIndex++;\n            else\n                colIndex--;\n        }\n        \n        return false;\n    }    \n}\n```\n
['Binary Search', 'Java']