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

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ต.ค. 2024

ความคิดเห็น • 21

  • @ARYANMITTAL
    @ARYANMITTAL  5 หลายเดือนก่อน +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 = th-cam.com/video/SmxdebjWvfs/w-d-xo.html
    (Write on YT - Leetcode 786 by Aryan Mittal) (Look at above's Video Time stamps for Min Heap approach)

  • @iamnoob7593
    @iamnoob7593 3 หลายเดือนก่อน

    Brilliant Presentation style is superb.

  • @devkumaracharyaiitbombay5341
    @devkumaracharyaiitbombay5341 4 หลายเดือนก่อน

    your intuition building is nice , 14:03

  • @muhiwaraa
    @muhiwaraa 5 หลายเดือนก่อน +1

    Keepp rocking ❤

  • @bharathkumar9645
    @bharathkumar9645 5 หลายเดือนก่อน

    Very well explained.

  • @NexInspireHub
    @NexInspireHub 5 หลายเดือนก่อน

    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 😍

  • @mandartule
    @mandartule 5 หลายเดือนก่อน +2

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

  • @phoddaal7130
    @phoddaal7130 5 หลายเดือนก่อน +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  5 หลายเดือนก่อน +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 5 หลายเดือนก่อน

      ​@@ARYANMITTAL Cool
      thank u
      You Are Awesome ❤

  • @ITACHIUCHIHA-dr8sz
    @ITACHIUCHIHA-dr8sz 5 หลายเดือนก่อน

    Will there be a video on todays leetcode POTD?

  • @learningmaths786
    @learningmaths786 5 หลายเดือนก่อน

    very good

  • @Idk-qg7hb
    @Idk-qg7hb 5 หลายเดือนก่อน

    Awesome

  • @rishavkumar7133
    @rishavkumar7133 5 หลายเดือนก่อน

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

  • @codingkart245
    @codingkart245 5 หลายเดือนก่อน

    Yaaaaay, First Comment!!!!!!

    • @ARYANMITTAL
      @ARYANMITTAL  5 หลายเดือนก่อน

      ❤️❤️ yeah coding kart broo 🫂

  • @user-orangeball
    @user-orangeball 5 หลายเดือนก่อน

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

  • @staywithmeforever
    @staywithmeforever 5 หลายเดือนก่อน +1

    Bro today's Leetcode problem 🥺

    • @ARYANMITTAL
      @ARYANMITTAL  5 หลายเดือนก่อน +2

      Already live on channel bro ❤️

    • @staywithmeforever
      @staywithmeforever 5 หลายเดือนก่อน

      @@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 5 หลายเดือนก่อน +2

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