My assumption is we can optimize the code even further by making use of the binary search and turning the runtime complexity to be logarithmic. Here is a sample code from leetcode submission: public boolean searchMatrix(int[][] matrix, int target) { int row_num = matrix.length; int col_num = matrix[0].length; int begin = 0, end = row_num * col_num - 1; while(begin
Sir, Thanks for your sharing! It is quite useful. By the way, could you please share how to solve the similar problem, "Kth Smallest Element in a Sorted Matrix"?
awesome explaination as always but you missed on the running time complexity of this approach, but i believe it will be O(n+m) time where n and m are rows and columns and space will be constant space!!!!!!!!
in the first example,it will return false if we search for 46, because 46>40 and row will get incremented. Also in the second example, same would happen for 21 and 31
best explanation on RUclips!!!
Sir thankyou for helping me to build the kind of logic i needed to solve this type of question...
My assumption is we can optimize the code even further by making use of the binary search and turning the runtime complexity to be logarithmic.
Here is a sample code from leetcode submission:
public boolean searchMatrix(int[][] matrix, int target) {
int row_num = matrix.length;
int col_num = matrix[0].length;
int begin = 0, end = row_num * col_num - 1;
while(begin
Excellent explanation sir.
Great walkthrough!
clear and nice explanation ..great work keep doing
I think the time complexity is O(min (m, n)) where m and n are rows and cols of the matrix respectively. Please correct me if I am wrong.
correct
I think worst time complexity will be O(m + n)
Sir, Thanks for your sharing! It is quite useful. By the way, could you please share how to solve the similar problem, "Kth Smallest Element in a Sorted Matrix"?
awesome explaination as always but you missed on the running time complexity of this approach, but i believe it will be O(n+m) time where n and m are rows and columns and space will be constant space!!!!!!!!
How n+m
bruh u saved my life
sir ur videos are very helpfull.
sir please upload a video on sudoku solving.backtraking !!please sir
what's the time complexity?
Sir iss form mai matrix ko sort kaise kiya hai?
Agar column wise sorting ki hai to last ke row mai error hai first two columns
please add more videos on matrix related problems
Thanks bro!
this is high quality!
sir, could you upload a video explaining solution of "longest alternatin(zig-zig) subsequence" please...
Thanks much!
🤟
thanks sir
This is failing for the input matrix {{-1,3}} and matrix{{1,1}} . Can you please tell me how to fix this?
Your matrix is not in increasing order.
Thanks😄
TIme complexity?
worst time complexity O(m+ n)
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
j = len(matrix) -1
i = 0
if j is None:
return 'false'
while i = 0:
if matrix[i][j] == target:
return 'true'
elif matrix[i][j] > target:
j -= 1
elif matrix[i][j] < target:
i += 1
return 'false'
can u correct my code?
in the first example,it will return false if we search for 46, because 46>40 and row will get incremented. Also in the second example, same would happen for 21 and 31