K Closest Points to Origin - Leetcode 973 - Heaps (Python)

preview_player
Показать описание


Please check my playlists for free DSA problem solutions:

My Favorite Courses:

Data Structures & Algorithms:

Python:

Web Dev / Full Stack:

Cloud Development:

Game Development:

SQL & Data Science:

Machine Learning & AI:
Рекомендации по теме
Комментарии
Автор

Master Data Structures & Algorithms For FREE at AlgoMap.io!

GregHogg
Автор

its so wonderful to realise that this heap DS is helping us to solve a problem that involves k smallest, k largest etc, by not doing a useless sorting all of the elements involved.

jmgpqcx
Автор

That is a really nice and easy to understand solution! But you can also use quick select to improve to O(n)

galdali
Автор

Great. One observation, if two are more points are within the square shaped region (1, 1) (-1, -1), then I guess we need to compare the square root of squared sum.

ganeshegmful
Автор

finally understood this problem, ty a lot!

kauegatto
Автор

What is the name of the software he uses as a blackboard?

tm-luk
Автор

return heapq.nsmallest(k, points, lambda p : math.sqrt(p[0]**2 + p[1]**2))

miramar-
welcome to shbcf.ru