First we check if number that we want to search can be in our matrix. If it can be in our matrix we start searching. We start searching from top left corner of matrix. Max number of moves we can make to find our number is n+m. Time Complexity : O(n+m)
First we check if number that we want to search can be in our matrix. If it can be in our matrix we start searching. We start searching from top left corner of matrix. Max number of moves we can make to find our number is n+m. Time Complexity : O(n+m)