The 3 Levels of Binary Search

preview_player
Показать описание
When most people think of Binary Search, they think of finding a number in a sorted array. And while that IS binary search, there's a lot more that you can do with it than that.

Especially in coding interviews when interviewers ask more involved problems, understanding the complexities of binary search can be really valuable.

In this video, I'll show you some of the different ways that you can apply binary search to interview problems.

RESOURCES & LINKS MENTIONED IN THIS VIDEO:

YOU CAN ALSO FIND ME HERE

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

Your lectures are great. Could you do more videos like this breaking it down from Easy to Hard levels? This is my first time engaging with your video channel!

emilypmendez
Автор

And that's not the end of it, A lot of problems have a "Hidden", or rather obscure Binary Search Solution. One good example is the "Kth Smallest element in a sorted Matrix" problem.

jlecampana
Автор

GREAT, pleaase more kind of this video

nasimajosefi
Автор

this is the only video available on youtube which talks about this concept

YuvrajPathak-dmgi
Автор

Great lecture! I wonder if we can optimize the last problem using a running sum.

Alexsc
Автор

you are a legend amongst algo tutors.
recent business graduate. have technical interviews with apple and amazon. (project managers liked my side projects). also have been coding since a kid.
have never taken an exam for algos + ds. and you have helped me tremendously this week.
the array tricks / middle school math i learnt earlier is golden!

tibettenballs
Автор

The most important part (3) is underelaborated

ic
Автор

I'm not understanding how 2 is less than 7 but 1 is greater than 7.. shouldn't 2 be greater than 7 also?

Girlgetup__
Автор

arr = list(map(int, input().split()))
num = int(input())

l = 0
r = len(arr) - 1
cnt = 0

while l <= r:
m = (l + r) // 2

if num == arr[m]:
cnt = 1
break
elif arr[l] < arr[m]:
if arr[l] <= num < arr[m]:
r = m - 1
else:
l = m + 1
else:
if arr[l] <= num or num < arr[m]:
r = m - 1
else:
l = m + 1

if cnt == 1:
print(m)
else:
print(-1)

fantasy
Автор

I wanted to watch the video but your light mode screen is blinding me. Please use a black slate

coldspine