Dev HUMILIATED after writing Brute Force Search on a Sorted List

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


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

Kinda surprised how many people think it's a Linked List.. does this look familiar:

List<> list = new ArrayList<>();

NeetCodeIO
Автор

Bro was able to identify the Leetcode number from the top of his head💀

taaaaaaay
Автор

For small arrays, linear search actually beats binary search because it's so branch-prediction friendly.

LandoKalrissian
Автор

When do you ever use binary search in a real project?
It's either dictionary lookup or flat list.
99% of our performance issues are crappy sql queries, a bad coded UI framework, or just plain logic errors.
If binary search is your problem then it looks like your project is in an AMAZING state!

GnomeEU
Автор

did he just fucking quote a LEETCODE question with NUMBER by looking 4 lines of code!!! 😭😭

halfjainam
Автор

Discussion of performance without mentioning CPU caching is ... interesting.

LukeDrumm
Автор

2:30 No, in Java the syntax to get a value from an Array (as you said) is array[index]. However to get value from a List, you'd use .get(index) as you can see in the vid.

justADeni
Автор

I think the more embarrassing thing is the person using a Windows laptop at 1:18

NeetCodeIO
Автор

there are actually quite a few languages that better to use method to get an element with index. Because with [ ] most programming languages will just panic / throw exception when index out of bound, but with method like .get() we can make the return type not the bare element but a wrapper like Option<T> in rust so Some(value) if the value is present and None if the index is out of bound

limm
Автор

If I was getting grilled like that I would have just said that in spite of the list saying it was sorted there was no guarantee so I had to check manually. Might work 😂

n_x
Автор

Well, to be pedantic, without knowing the type of sortedList (assumed in the show to be an array, hence the joke) which could've been a LinkedList, we cannot really comment on the efficiency of this code. Binary search on a linked list is worse than linear search.

vinayemani
Автор

Hey! l +r ?? You will get integer overflow!

romanivanov
Автор

3:44 (l + r)/2 would cause overflow for big arrays

fromjavatohaskell
Автор

it's not a mistake, it's being frugal with your time when the complexity doesnt affect the runtime for fuck. if he's searching a list of size 3 then the complexity doesnt matter. this tv show fucking sucks, no one acts like a software dev. painful to watch

SuperMaDBrothers
Автор

There also seems to be a bug in the solution from the clip - it always tries to get the first element from the sortedList? What if the list is empty?

GMDeatHSoul
Автор

I see myself using linear search under pressure, it just seems like the most natural way of searching in non computed primitive way of searching items in real life, of course in a real situation the best method would be using a built in search mechanism of the language such as the .indexOf() or its equivalent if present in the language and let the compiler or the interpreter get clever with it if not implement a more sophisticated searching algorithm more fitting for the expected data size.

For me the problem in the video is not the error itself but rather the reaction to the errors. We all make mistakes, especially in the beginning but instead of putting each other down over it we should be correcting each other while lifting each other up. Unfortunately I have seen this kind of snobbery in real life. Pressuring devs into making untested solutions that even they couldn't revise themselves to get solutions and then talk them down for mistakes.

ofbaran
Автор

Fuccc I think I need a refresh on algorithms, I use them so rarely I keep forgetting how they work lol

mycommentmyopinion
Автор

I think you forgot about the fact that (l+r)/2 might cause the integer to overflow. I know that solving the problem is not the point of the video. But I’m just putting it in here.

technophile_
Автор

Java allows direct array access(I don't think any language doesn't since the purpose of an array is data storage in memory sequence), Java's arrays are implemented as objects, nums[5] = 69 is a valid assignment.

TacoMaster
Автор

How do you even perform binary search on a linked list? Random access iterators are not available

sunnyyasser