Search an element in sorted Matrix( row and column sorted)

Sdílet
Vložit
  • čas přidán 28. 07. 2017
  • Search an element in sorted Matrix( row and column sorted). We are making use of the sorted nature of rows and columns. Very Efficient technique.

Komentáře • 30

  • @HeroesOfAesthetics
    @HeroesOfAesthetics Před 3 lety +1

    best explanation on CZcams!!!

  • @Pratimbiswasss
    @Pratimbiswasss Před rokem

    Sir thankyou for helping me to build the kind of logic i needed to solve this type of question...

  • @nitishiter
    @nitishiter Před 6 lety +3

    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

  • @gauravparkash162
    @gauravparkash162 Před 6 lety

    clear and nice explanation ..great work keep doing

  • @gujjulapradeepreddy3189

    Excellent explanation sir.

  • @nishadkumar7322
    @nishadkumar7322 Před 3 lety

    Great walkthrough!

  • @jjddpphh
    @jjddpphh Před 4 lety +1

    bruh u saved my life

  • @lineage-darkelf
    @lineage-darkelf Před 5 lety +4

    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"?

  • @MrMarkgyuro
    @MrMarkgyuro Před 4 lety

    this is high quality!

  • @haria8779
    @haria8779 Před 4 lety

    Thanks much!

  • @koushikchiku5015
    @koushikchiku5015 Před 7 lety +3

    sir ur videos are very helpfull.
    sir please upload a video on sudoku solving.backtraking !!please sir

  • @Huntyoudown2020
    @Huntyoudown2020 Před 10 dny

    🤟

  • @algorithmimplementer415
    @algorithmimplementer415 Před 4 lety +3

    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.

  • @praveenchouhan6388
    @praveenchouhan6388 Před 4 lety +1

    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!!!!!!!!

  • @priyadebnath6896
    @priyadebnath6896 Před 6 lety

    Thanks😄

  • @the-gray-haired-developer

    please add more videos on matrix related problems

  • @fsbonilha
    @fsbonilha Před 3 lety

    Thanks bro!

  • @pravesh8187
    @pravesh8187 Před 5 lety

    thanks sir

  • @mukhtarali1318
    @mukhtarali1318 Před 7 lety +1

    sir, could you upload a video explaining solution of "longest alternatin(zig-zig) subsequence" please...

  • @VishalGupta_5083
    @VishalGupta_5083 Před 3 lety

    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

  • @anmolgautam19
    @anmolgautam19 Před 4 lety

    what's the time complexity?

  • @arunreddy5607
    @arunreddy5607 Před 6 lety

    This is failing for the input matrix {{-1,3}} and matrix{{1,1}} . Can you please tell me how to fix this?

    • @gokul5293
      @gokul5293 Před 5 lety

      Your matrix is not in increasing order.

  • @vikrantsanke3554
    @vikrantsanke3554 Před 6 lety +1

    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

  • @sumanthchowdary9699
    @sumanthchowdary9699 Před 3 lety

    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?

  • @kiranmahajan778
    @kiranmahajan778 Před 4 lety

    TIme complexity?