Тёмный

Coding Interview: Find K Closest Elements 

James Cutajar
Подписаться 13 тыс.
Просмотров 3,6 тыс.
50% 1

Introduction and solution on the Find K Closest Elements coding interview. Variations of this algorithm have been asked by a few big tech companies such as Google, Facebook, Microsoft, Netflix, Amazon, so it's important to know how to solve it efficiently.
Please support me through my Udemy courses:
Pass your coding interview in,
Java : www.udemy.com/...
Python: www.udemy.com/...
Ruby: www.udemy.com/...
JavaScript: www.udemy.com/...
Multithreading in,
Go Lang: www.udemy.com/...
Python: www.udemy.com/...
Java: www.udemy.com/...
Learn Dynamic Programming in,
Java: www.udemy.com/...
Python: www.udemy.com/...
Ruby: www.udemy.com/...

Опубликовано:

 

9 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 7   
@shristisrivastava7054
@shristisrivastava7054 12 дней назад
Very clear explanation. Thanks for posting this video.
@empowercode
@empowercode 2 года назад
Hey James, great video! Particularly, I like how clear and detailed your explanations are as well as the depth of knowledge you have surrounding the general programming approach. Since I run a tech education channel as well, I love to see fellow Content Creators sharing, educating, and inspiring a large global audience. Keep up the great work!
@lvkaz
@lvkaz 2 года назад
This content is so underrated! Keep up the excellent work. I hope You will get a lot of recognition soon for such great explanations!
@vijayakumareyunni6010
@vijayakumareyunni6010 10 месяцев назад
Excellent explanation and solution
@Adaetro
@Adaetro 2 года назад
Since array is ordered what if you stop the cycle when current abs_sum is higher then previous abs_sum? In the first example since abs_sum of [8 , 9, 10] = 3 and previous abs_sum of [7, 8, 9] = 2 then there is no point in calculating [9, 10, 13] since abs_sum is only going to increase from now on?
@Adaetro
@Adaetro 2 года назад
def find_closest_elements(arr, k, x): abs_list = list(map(lambda n:abs(n-x), arr)) prev_abs_sum = abs_sum_min = abs_sum = sum(abs_list[0:k]) min_i = 0 for i in range(1, len(arr)-k+1): abs_sum = abs_list[i+k-1] + abs_sum - abs_list[i-1] if prev_abs_sum < abs_sum: break if abs_sum < abs_sum_min: abs_sum_min = abs_sum min_i = i prev_abs_sum = abs_sum return arr[min_i:min_i+k], i #print number of loops print(find_closest_elements([5, 7, 8, 9, 10, 13], k=3, x=8))
@yashchoube576
@yashchoube576 Год назад
Best
Далее
Go Lang's Mutex for Thread Synchronization
9:00
Просмотров 2,8 тыс.
Sigma Girl Pizza #funny #memes #comedy
00:14
Просмотров 1,7 млн
Google Coding Interview With A Competitive Programmer
54:17
Bug in Binary Search - Computerphile
11:31
Просмотров 285 тыс.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Knuth Shuffle made simple in 5 mins
5:29
Просмотров 9 тыс.
The 3 Levels of Binary Search
22:06
Просмотров 15 тыс.
Find K Closest Elements | LeetCode 658 | Coders Camp
10:40
Python's Thread Barriers in 8 mins
8:50
Просмотров 3 тыс.
Find Peak Element - Leetcode 162 - Python
11:02
Просмотров 39 тыс.
Fast Inverse Square Root - A Quake III Algorithm
20:08