Leetcode 378. Kth Smallest Element in a Sorted Matrix - Binary Search

Поділитися
Вставка
  • Опубліковано 16 січ 2025

КОМЕНТАРІ • 16

  • @muskanmall4401
    @muskanmall4401 Місяць тому +1

    OMG! this is the only video where i understood the counting logic!!

  • @safalsinha1982
    @safalsinha1982 2 роки тому +3

    Great explaination🔥 Understood everything....its great you are explaining every little things so there is no confusion.

  • @ABHISHEK0058
    @ABHISHEK0058 2 роки тому +3

    Great job

  • @Rahul-pr1zr
    @Rahul-pr1zr Рік тому

    How did you come up with the idea of choosing the bottom left or top right for calculating the no. of elements

  • @rickc-1375
    @rickc-1375 2 роки тому +2

    SUBSCRIBED! Best explanation of this problem out there. I appreciate you explaining every little detail. Looking forward to more content, thanks bro!
    One minor enhancement would be to put a little more effort in the visual explanation, I know it sucks drawing out stuff but it helps us and it helps you (more watch time haha). Either way man, thanks!

  • @Gaurav_kumar_mgk
    @Gaurav_kumar_mgk 2 роки тому +1

    very great explanation KC **

  • @michaelbachmann457
    @michaelbachmann457 Рік тому +1

    best explanation out there

  • @Gaurav_kumar_mgk
    @Gaurav_kumar_mgk 2 роки тому +2

    for candidate 13, less or equal count is 11 at 3:00min

  • @douglascheng9794
    @douglascheng9794 2 роки тому +1

    great explanation

    • @douglascheng9794
      @douglascheng9794 2 роки тому

      btw u kinda look like young might guy lool

    • @KacyCodes
      @KacyCodes  2 роки тому

      @@douglascheng9794 As long as it’s 8 gates Might Guy lmao

  • @ABHISHEK0058
    @ABHISHEK0058 2 роки тому +2

    Please zoom in while coding. It helps

    • @KacyCodes
      @KacyCodes  2 роки тому +1

      I was thinking the same thing. I’ll zoom in for future vids.

  • @hananraza1218
    @hananraza1218 2 роки тому +1

    Excellent!

  • @sannge6471
    @sannge6471 2 роки тому

    Hi, Why could we guarantee that we can find the kth value in the matrix? I was confused about that since the start. Great explanation btw.

    • @KacyCodes
      @KacyCodes  2 роки тому +1

      I feel like I had that same question when I first did this problem but I don’t remember why.
      So the idea is we’re binary searching for the smallest value that results in a # of elements >= k.
      Whenever we test a candidate kth value, we check if the # of elements is >= k. If it is, record the candidate value and try a smaller candidate.
      If the smaller candidate also results in the # of elements being >= k, then record the new candidate.
      If the smaller candidate value results in the # of elements being < k, then we try a bigger candidate. Eventually we rule out all possibilities in the binary search, and the last value we recorded must be the smallest kth value that results in a # of elements >= k.
      At every iteration we’re honing in on the smallest kth value that satisfies our condition of having >= k elements.
      I would listen to the beginning again where I go over that example I came up with.