Kth Smallest Element in a Sorted Matrix | Leetcode 378 | Live Coding Session

Here is the solution to "Kth Smallest Element in a Sorted Matrix" leetcode question. Hope you have a great time going through it.
Question : leetcode.com/problems/kth-sma...
Prerequisite problems: leetcode.com/problems/search-...
Chapters
1) 0:00 Explaining the problem out loud
2) 1:10 Question walkthrough
3) 2:30 Algorithm using PriorityQueues
4) 4:30 Algorithm using Binary Search
Prerequisite problems:
leetcode.com/problems/search-...
leetcode.com/problems/first-b...
5) 9:00 Coding it up
Solutions: github.com/Sunchit/Coding-Dec...
For discussion/feedback
Feel free to join discord / discord
Complete July playlist : • Leetcode July 2021 Cha...
Complete June playlist : • Leetcode June 2021 Cha...
Complete May playlist : • Leetcode May 2021 Chal...
Complete April playlist : • Leetcode April 2021 Ch...
Complete March playlist : • Playlist
Complete Feb playlist : • Leetcode February 2021...
Complete Jan playlist : • Leetcode January 2021 ...
Complete December Playlist: • Leetcode December 2020...
PS : Please increase the speed to 1.25X

Пікірлер: 40

  • @CodeWithSunchitDudeja
    @CodeWithSunchitDudeja3 жыл бұрын

    In the complexity part where I explained it is nlogk, n here stands for total elements in the matrix, which is actually n2.

  • @ritwik121

    @ritwik121

    3 жыл бұрын

    whats the time complexity of binary search approach?

  • @sanchitkhare7977
    @sanchitkhare79773 жыл бұрын

    Please explain the time complexity of the second solution.

  • @laxminiharika4116
    @laxminiharika41162 жыл бұрын

    At 11.04, how are we sure that low will hold the kth smallest element in matrix?

  • @dede6110
    @dede61102 жыл бұрын

    which leetcode you mean in 3:50 get rank of a number in sorted matrix? 1632?

  • @PuneetKumar-uq4ru
    @PuneetKumar-uq4ru2 жыл бұрын

    when i am doing (lo+hi)/2 instead of lo + (hi-lo)/2 i am getting TLE , what is the reason for this. i am getting TLE and last excuted input is[[-5,-4],[-5,-4]] 2.

  • @sourin.majumdar

    @sourin.majumdar

    2 жыл бұрын

    To understand why this happened watch: kzread.info/dash/bejne/mGqJt5mPY9bghto.html from 29:21

  • @saunaknandi1814
    @saunaknandi18142 жыл бұрын

    TC - for BS -> O(2*N*log(MAX-MIN)) - MAX= MAX VALUE AND MIN IS MIN VALUE

  • @tushar_agarwal_it_2nd_a_477
    @tushar_agarwal_it_2nd_a_4772 жыл бұрын

    Hi ,How can we be sure that the kth element we got after bs will be there in the matrix ?

  • @gopinathsikha

    @gopinathsikha

    2 жыл бұрын

    Binaray search is finding the leftmost answer suitable so, we are good. {9,10,11,13}, and k = 3, if mid is 12, we will not stop at 12, we again to another round to get 11(which is leftmost). Eventually we will stop only at 11.

  • @tushar_agarwal_it_2nd_a_477

    @tushar_agarwal_it_2nd_a_477

    2 жыл бұрын

    @@gopinathsikha Yes got it thanks:)

  • @KirtiSingh-cm4up
    @KirtiSingh-cm4up3 жыл бұрын

    Sir , time complexity for the heap solution is nlogk or n2logk... please tell

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    3 жыл бұрын

    N2 log k, n2 are the total elements in the matrix

  • @siddharth4069
    @siddharth40692 жыл бұрын

    Thank you :)

  • @tathagatnegi5923
    @tathagatnegi59233 жыл бұрын

    Thanks

  • @rknarayan8236
    @rknarayan8236 Жыл бұрын

    Woahhhhh . Crystal Clear

  • @jessanraj9086
    @jessanraj90862 жыл бұрын

    Awesome 🔥

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    Glad you like it

  • @santoshvarma996
    @santoshvarma9963 жыл бұрын

    hi thanks for the videos. can you please increase the sound of your voice in the videos, if possible.

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    3 жыл бұрын

    Sure, need some suggestions any idea how?

  • @santoshvarma996

    @santoshvarma996

    3 жыл бұрын

    the music in the starting is audible clearly but once you start speaking it goes low, may be it is my perception you can check it once from your end as well. thanks for the reply

  • @harpreets1602

    @harpreets1602

    3 жыл бұрын

    @@CodeWithSunchitDudeja sir you can use the mikes of earphone ,headphone, mobile app or the professional mike.

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    3 жыл бұрын

    @@harpreets1602 Any recommendations, economical and good in quality.

  • @harpreets1602

    @harpreets1602

    3 жыл бұрын

    @@CodeWithSunchitDudeja sir I have only used earphones and headphones, they work fine for me. But haven't used that professional Mike

  • @krateskim4169
    @krateskim41692 жыл бұрын

    Awesome

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    Thanks

  • @bikkysharma7253
    @bikkysharma72532 жыл бұрын

    nice

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    Thanks

  • @wintersol9921
    @wintersol99212 жыл бұрын

    How come the priority queue solution is O(n log k)? You have a nested for loop with both of them iterate from 0 until n. It should be O(n^2). Am I wrong?

  • @cinimodmil

    @cinimodmil

    2 жыл бұрын

    yeah i think it's O(n^2) too

  • @varaprasaddudi9842

    @varaprasaddudi9842

    7 ай бұрын

    overall number are n only na

  • @anandpandey4463
    @anandpandey44632 жыл бұрын

    7:35 Count of mid=14 will be 8, since there are only 8 elements smaller than 14. Isn't it?

  • @shivalikagupta3433

    @shivalikagupta3433

    2 жыл бұрын

    yes but its rank is 9, we need 8th smallest, that is its position should be 8.

  • @anandpandey4463

    @anandpandey4463

    2 жыл бұрын

    8:20 Yeah, it makes sense, but while searching for the rank of 13, ie mid = 13, there are 8 elements smaller than or equal to mid. It's count is 8, but it's rank should be 9 then, because the position here is 9. Isn't it? Also when we dry run the code, there will be one more step, when high will be set as mid, ie 13. Here low will be equal to high and thus loop ends, and when we return low, we will get our ans as 13.

  • @jayneversettle
    @jayneversettle2 жыл бұрын

    Todays daily LeetCode challenge.

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    Yes

  • @osiris1102
    @osiris11022 жыл бұрын

    Please use something better to write like a stylus and improve sound quality, the audio is too low.

  • @subee128
    @subee128Ай бұрын

    Thanks