378. Kth Smallest Element in a Sorted Matrix | Priority Queue | Binary Search on Answer

Поделиться
HTML-код
  • Опубликовано: 4 дек 2024

Комментарии • 21

  • @ARYANMITTAL
    @ARYANMITTAL  6 месяцев назад +5

    One major optimisation in priority queue approach i missed, which is optimising O(n*m*log(k)) to O(k*log(k)), this can be achieved using Priority Queue (this time Min Heap), in which =
    .
    Intuition - Remove smallest k-1 elements then, what so ever is remaining first element in data-structure is kth smallest Element. [Remove smallest element - Min Heap]
    .
    Step1 - Push column0 all elements in Min Heap.
    Step2 - Start removing elements from above Min Heap [remove k-1 elements], on each removal size of min Heap will decrease by 1, so add next element in that same row to min Heap to make size of min Heap back to K.
    Step 3 - After applying above operation k-1 times, we will be left with data structure having k or less elements, but top of that min heap will be kth Smallest element.
    time complexity = O(n + klog(k))
    Documentation with Diagram (Solution 2) - tinyurl.com/24lnp87w
    .
    Video Dry Run of this approach in this Video = ruclips.net/video/SmxdebjWvfs/видео.html
    (Write on YT - Leetcode 786 by Aryan Mittal) (Look at above's Video Time stamps for Min Heap approach)

  • @iamnoob7593
    @iamnoob7593 5 месяцев назад +1

    Brilliant Presentation style is superb.

  • @devkumaracharyaiitbombay5341
    @devkumaracharyaiitbombay5341 5 месяцев назад

    your intuition building is nice , 14:03

  • @bharathkumar9645
    @bharathkumar9645 6 месяцев назад

    Very well explained.

  • @muhiwaraa
    @muhiwaraa 6 месяцев назад +1

    Keepp rocking ❤

  • @NexInspireHub
    @NexInspireHub 6 месяцев назад

    We can also do this in O(n) time complexity, leetcode has given a research paper pdf in their question, by the way. Nice Explanation 😍

  • @learningmaths786
    @learningmaths786 6 месяцев назад

    very good

  • @Idk-qg7hb
    @Idk-qg7hb 6 месяцев назад

    Awesome

  • @phoddaal7130
    @phoddaal7130 6 месяцев назад +1

    Aryan Bhai Binary Search ke upar bhi Crash Course Nikaalon Please,
    badi confusion hoti hai
    ki
    right = mid
    karna hai ya
    right = mid -1
    aaj ke daily ke editorial mein bhi yahi confusion hui

    • @ARYANMITTAL
      @ARYANMITTAL  6 месяцев назад +3

      Nhi bhai, in my solutions it is always mid-1, i never taught to take high as mid, thus we follow same template in all binary search questions, low is always mid + 1. But yeah, a crash course on this is also very important. ( will be soon live on codewithAryan channel )❤️🫂

    • @phoddaal7130
      @phoddaal7130 6 месяцев назад

      ​@@ARYANMITTAL Cool
      thank u
      You Are Awesome ❤

  • @mandartule
    @mandartule 6 месяцев назад +2

    I have noticed, bro you have stopped hiding the company names.

  • @user-orangeball
    @user-orangeball 6 месяцев назад

    When I find an answer in the interview is like: 16:10

  • @ITACHIUCHIHA-dr8sz
    @ITACHIUCHIHA-dr8sz 6 месяцев назад

    Will there be a video on todays leetcode POTD?

  • @rishavkumar7133
    @rishavkumar7133 6 месяцев назад

    damn i used quickselect which is almost as good as bimary search on answers

  • @codingkart245
    @codingkart245 6 месяцев назад

    Yaaaaay, First Comment!!!!!!

    • @ARYANMITTAL
      @ARYANMITTAL  6 месяцев назад

      ❤️❤️ yeah coding kart broo 🫂

  • @staywithmeforever
    @staywithmeforever 6 месяцев назад +1

    Bro today's Leetcode problem 🥺

    • @ARYANMITTAL
      @ARYANMITTAL  6 месяцев назад +2

      Already live on channel bro ❤️

    • @staywithmeforever
      @staywithmeforever 6 месяцев назад

      @@ARYANMITTAL Bro can we make a video on basics of every data structure like what is priority queue , max heap like that for some important data structures. I know there are many vedios but your explanation is soooo good even I code in python I watching and able to understand.

  • @Kaviarasu_NS
    @Kaviarasu_NS 6 месяцев назад +2

    Greate your posting such awesome content, but I don't like the way you over express things in your video