# [Search in a row wise and column wise sorted matrix](https://leetcode.com/problems/search-a-2d-matrix/)
## Problem statement
Given an n x n matrix and an integer x, find the position of x in the matrix if it is present. Otherwise, retun “false”.
Every row and column of the matrix is sorted in increasing order. The designed algorithm should have linear time complexity.
# solution approach
* The idea is to start seaching from top right cell of the matrix.
* if the current cell value is cell then what we need, since, we are coming from top **right** the only option remains is to go down, in the matrix(do i++)
* if the current cell has a value more then the target, then ,go left.
* return true if your found the value false otherwise
# Code
```c++17
class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
int row = matrix.size();
int col = matrix[0].size();
int i=0,j=col-1;
while(i<row and j>=0){
if(matrix[i][j]>target)
j--;
else if(matrix[i][j]<target)
i++;
else
return true;
}
return false;
}
};
```