⭐ Binary Search - Time Complexity + Space Complexity + Explanation ⭐
Another version of this problem: https://leetcode.com/problems/search-a-2d-matrix/\nSolution: https://leetcode.com/problems/search-a-2d-matrix/discuss/2760040/B
Another version of this problem: https://leetcode.com/problems/search-a-2d-matrix/\nSolution: https://leetcode.com/problems/search-a-2d-matrix/discuss/2760040/Binary-Search-Time-Complexity-%2B-Space-Complexity-%2B-Explanation\n\nTime Complexity - At most, we can traverse the length of 0 to row and col to 0. Thus time taken is O(row + col).\nSpace Complexity - Space taken is O(1).\nExplanation - We start at the top right corner of the matrix, and move left/right according to whether the current value is greater or lesser than target. This uses the property of each row and column being sorted.\n\n```\nclass Solution {\npublic:\n    bool searchMatrix(vector<vector<int>>& matrix, int target) {\n        int row = matrix.size(), col = matrix[0].size(), i = 0, j = col - 1;\n        while(i < row && j >= 0){\n            if(matrix[i][j] == target) return true;\n            else if(matrix[i][j] > target) j--;\n            else i++;\n        }\n        return false;\n    }\n};\n```\n\nKindly upvote if you found the solution helpful :)\n**For more such explanations of LeetCode problems along with their C++ solutions:**\nhttps://github.com/Arya-Gupta/LeetCode
['Array', 'Binary Search', 'C', 'Matrix', 'Binary Tree', 'C++']