Leetcode 378. Kth Smallest Element in a Sorted Matrix [Java]
ฝัง
- เผยแพร่เมื่อ 22 ส.ค. 2024
- "Kth Smallest Element in a Sorted Matrix" is the coding interview question asked by Amazon. Check out this video to find out how to solve it efficiently using the binary search in Java.
Question URL: leetcode.com/p...
Please write in the comments below which leetcode problem you want me to solve next.
And remember, a leetcode a day keeps unemployment away!
Thanks for watching!
#leetcode378 - วิทยาศาสตร์และเทคโนโลยี
Thank you so much. This video was really helpful to understand how the binary search solution worked.
I am very happy that I was able to help you! Thanks for watching!
@@ifelsestatement7803 Hey, I am still not sure abt time complexity. The binary search actually depend on the value of the smallest and largest element of the matrix so time complexity will actually depend on the values?
watched a lot of videos on repeat but your video made it crystal clear in one go... THANK YOU keep it up loved it
Thank you so much for your comment! I am very glad it helped you!
Great explanation, thank you so much.
I am glad it helped you! Thak you for your comment!
Appreciate your explanation, very clear.
Glad it was helpful to you! Thanks!
Nice solution!
Thanks!
Thank you. Can you make a list of mediums you had please? Also do you have a list of mid-hard questions you would recommend preparing for interview please?
I will add it to my to-do list to make these playlists. In a meantime, definitely check out:
1) 322. Coin Change
2) 518. Coin Change 2
3) 647. Palindromic Substrings
4) 475. Heaters
5) 542. 01 Matrix
6) 46. Permutations
in the countLessOrEqual function, why is the starting point in the right most column?
Thank you for this video by the way, greatly appreciated!
you look like luka doncic
Thank you! ;D
great!!! what's the TC of the last approach?
thanks
You are welcome!
gj!!
isn't the middle element (min + max)/2?
The middle is calculated in this way so as to avoid Integer Overflow. Adding 2 integers may produce a value which exceeds the acceptable integer limits. Hence we calculate the mid in this manner.
min + (max - min)/2 == (min + max)/2
conceptually it is true. But when implemented as (min+max)/2, the result may overflow as we have a permissible range for any datatype. For example, (2147483600+2147483647)/2 would overflow, while 2147483600+(2147483647-2147483600)/2 won't. Mathematically, both are equivalent.
@@pratishbarthwal465 good point