[Java] Leetcode 658. Find K Closest Elements [Binary Search #8]

preview_player
Показать описание
In this video, I'm going to show you how to solve Leetcode 658. Find K Closest Elements which is related to Binary Search.

Here’s a quick rundown of what you’re about to learn:

⭐️ Course Contents ⭐️
⌨️ (0:00) Question
⌨️ (3:01) Solution Explain
⌨️ (12:57) Code

In the end, you’ll have a really good understanding on how to solve Leetcode 658. Find K Closest Elements and questions that are similar to this Binary Search.

Рекомендации по теме
Комментарии
Автор

very good explanation 5:46 this is where i didn't get it. im glad i found this video

sproutboot
Автор

Best explained solution for this problems I have ever found. Thank you for the work!

DongmingWu-ex
Автор

great video! thanks for sharing. It'd be better if you could explain (14:25) why one one condition, it's left = mid + 1, while right = mid on the other ?

pengx
Автор

It's good. Just that it would be great if you would have added the reason as to why we move (r = mid) and not (r = mid-1).
I think that's that part in Binary Search related problems where many people get confused.

And Thanks for the video. It was great.

mazhar
Автор

Didn't pass the test case: [1, 1, 2, 2, 2, 2, 2, 3, 3] 3 3. "right = arr.length - k" excluded the most right part of the array got checked.

wendywang
Автор

Isn't the first solution O(log n + k)? Cuz we might end up having to compare nearly all numbers in the array depending on k.

borazanabi