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

Sdílet
Vložit
  • čas přidán 8. 05. 2024
  • In this video, I'll talk about how to solve Leetcode 378. Kth Smallest Element in a Sorted Matrix | Priority Queue | Binary Search on Answer
    Leetcode 74. Search a 2D Matrix II Binary Search II Binary Search Tree - • Leetcode 74. Search a ...
    Let's Connect:
    📱Discord (Join Community) : / discord
    📝Linkedin: / aryan-mittal-0077
    📸 Instagram: / codewitharyanbhai
    💻 Twitter - / aryan_mittal007
    🤖 Github: github.com/aryan-0077
    About Me:
    I am Aryan Mittal - A Software Engineer in Goldman Sachs, Speaker, Creator & Educator. During my free time, I create programming education content on this channel & also how to use that to grow :)
    ✨ Hashtags ✨
    #programming #Interviews #leetcode #faang #maang #datastructures #algorithms

Komentáře • 21

  • @ARYANMITTAL
    @ARYANMITTAL  Před 2 měsíci +4

    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 = czcams.com/video/SmxdebjWvfs/video.html
    (Write on YT - Leetcode 786 by Aryan Mittal) (Look at above's Video Time stamps for Min Heap approach)

  • @kcecse
    @kcecse Před 2 měsíci +1

    Keepp rocking ❤

  • @iamnoob7593
    @iamnoob7593 Před 26 dny

    Brilliant Presentation style is superb.

  • @devkumaracharyaiitbombay5341

    your intuition building is nice , 14:03

  • @bharathkumar9645
    @bharathkumar9645 Před 2 měsíci

    Very well explained.

  • @NexInspireHub
    @NexInspireHub Před 2 měsíci

    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 Před 2 měsíci +2

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

  • @Idk-qg7hb
    @Idk-qg7hb Před 2 měsíci

    Awesome

  • @codingkart245
    @codingkart245 Před 2 měsíci

    Yaaaaay, First Comment!!!!!!

    • @ARYANMITTAL
      @ARYANMITTAL  Před 2 měsíci

      ❤️❤️ yeah coding kart broo 🫂

  • @learningmaths786
    @learningmaths786 Před 2 měsíci

    very good

  • @rishavkumar7133
    @rishavkumar7133 Před 2 měsíci

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

  • @ITACHIUCHIHA-dr8sz
    @ITACHIUCHIHA-dr8sz Před 2 měsíci

    Will there be a video on todays leetcode POTD?

  • @phoddaal7130
    @phoddaal7130 Před 2 měsíci +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  Před 2 měsíci +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 Před 2 měsíci

      ​@@ARYANMITTAL Cool
      thank u
      You Are Awesome ❤

  • @user-orangeball
    @user-orangeball Před 2 měsíci

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

  • @staywithmeforever
    @staywithmeforever Před 2 měsíci +1

    Bro today's Leetcode problem 🥺

    • @ARYANMITTAL
      @ARYANMITTAL  Před 2 měsíci +2

      Already live on channel bro ❤️

    • @staywithmeforever
      @staywithmeforever Před 2 měsíci

      @@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 Před 2 měsíci +2

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