K Closest Points to the Origin | Brute Force, Sorting, Heaps, & Reduction

  Рет қаралды 3,362

Interview Pen

Interview Pen

Күн бұрын

Visit Our Website: interviewpen.c...
Join Our Discord (24/7 help): / discord
Join Our Newsletter - The Blueprint: theblueprint.d...
Like & Subscribe: / @interviewpen
This is an example of a full video available on interviewpen.com. Check out our website to find more premium content like this!
Problem Statement:
Given an array of points `points` where points[i] = [xᵢ, yᵢ] represents a point on a [Cartesian plane](en.wikipedia.o...) and an integer `k`, return the `k` closest points to the origin (0, 0).
Point Distance: The distance between any two points A (point 1) & B (point 2) is given by the [Euclidean distance](en.wikipedia.o...) → sqrt((x₁ - x₂)² + (y₁ - y₂)²)
You may return the `k` closest points in any order.
Table of Contents:
0:00 - Problem Introduction
0:44 - Point-to-Point Distance
3:00 - Visit interviewpen.com
3:19 - Initial Thoughts
04:55 - Reducing to “Find K Smallest Items”
05:41 - Continuing On
06:02 - Picking the K Smallest Distances
06:33 - Implementation: Picking w/ Scans
09:02 - Complexities
09:54 - Implementation: Sorting → Plucking 1st k Items
10:47 - Complexities
11:01 - Using a Special Structure
11:53 - Using a Min Heap
12:43 - Using a Max Heap
13:44 - Implementation: Max Heap → Retain k Items
15:11 - Complexities
16:17 - Wrap Up
Erratum:
0:00 - The point written (0, 5) is (5, 0). This is verbally corrected at 2:41.
Socials:
Twitter: / interviewpen
Twitter (The Blueprint): / theblueprintdev
LinkedIn: / interviewpen
Website: interviewpen.c...

Пікірлер
@interviewpen
@interviewpen Жыл бұрын
Thanks for watching! (see our description for an Erratum) Visit interviewpen.com/? for more great Data Structures & Algorithms + System Design content 🧎
@ericmargolis1852
@ericmargolis1852 7 ай бұрын
Really good explanation and walkthrough, thank you!
@interviewpen
@interviewpen 7 ай бұрын
Thanks!
@mav31415
@mav31415 Жыл бұрын
nit: you can skip the square root and you'd get the same ordering.
@interviewpen
@interviewpen Жыл бұрын
makes sense, as we're just interested in a raw comparable magnitude vs. the actual distance -> if both line up then we solve the same problem indeed
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 192 М.
Disjoint-Set Data Structure (Union-Find) | Fast Subset Checking
18:43
UFC 287 : Перейра VS Адесанья 2
6:02
Setanta Sports UFC
Рет қаралды 486 М.
#behindthescenes @CrissaJackson
0:11
Happy Kelli
Рет қаралды 27 МЛН
БОЙКАЛАР| bayGUYS | 27 шығарылым
28:49
bayGUYS
Рет қаралды 1,1 МЛН
K CLOSEST POINTS TO ORIGIN | LEETCODE 973 | PYTHON SOLUTION
14:10
Cracking FAANG
Рет қаралды 2,4 М.
When to Use Kafka or RabbitMQ | System Design
8:16
Interview Pen
Рет қаралды 156 М.
I made Tetris in C, this is what I learned
15:15
Austin Larsen
Рет қаралды 22 М.
If you're ambitious but lazy, please watch this video...
12:57
Mark Tilbury
Рет қаралды 384 М.
What P vs NP is actually about
17:58
Polylog
Рет қаралды 145 М.
How To Learn Anything, Anywhere - Elon Musk
7:35
DB Business
Рет қаралды 4,6 МЛН
K Closest Points to Origin - Leetcode 973 - Heaps (Python)
9:47
When is a line nearest the origin?
7:50
Prime Newtons
Рет қаралды 9 М.
Programming with Math | The Lambda Calculus
21:48
Eyesomorphic
Рет қаралды 252 М.