Dev HUMILIATED after writing Brute Force Search on a Sorted List

Поділитися
Вставка
  • Опубліковано 12 лют 2024
  • 🚀 neetcode.io/ - A better way to prepare for Coding Interviews
    🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
    🐦 Twitter: / neetcode1
    ⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
    #neetcode #leetcode #python

КОМЕНТАРІ • 202

  • @NeetCodeIO
    @NeetCodeIO  5 місяців тому +70

    Kinda surprised how many people think it's a Linked List.. does this look familiar:
    List list = new ArrayList();

    • @rinat2160
      @rinat2160 5 місяців тому +1

      If you are writing a library which functions work reasonably well __only__ when Lists they accepting are ArrayLists, you are writing a bad library. If a function requires constant-time random iterators, it should only accept containers which have constant-time random iterators. That way compiler will prevent library users from using your library incorrectly.

  • @taaaaaaay
    @taaaaaaay 5 місяців тому +746

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

    • @chillsjiujitsu
      @chillsjiujitsu 5 місяців тому +42

      That’s why he’s the GOAT

    • @aflous
      @aflous 5 місяців тому +31

      His name is Neetcode, what did you expect?

    • @VampiricBard
      @VampiricBard 5 місяців тому +2

      @@aflous 🤣

    • @xcuu
      @xcuu 5 місяців тому

      Tell me you’re a sex haver without telling me you’re a sex haver

    • @kingpen5866
      @kingpen5866 5 місяців тому

      Bro

  • @LandoKalrissian
    @LandoKalrissian 5 місяців тому +462

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

    • @NeetCodeIO
      @NeetCodeIO  5 місяців тому +174

      Also why didnt he just do .indexOf(element)

    • @LandoKalrissian
      @LandoKalrissian 5 місяців тому +32

      ​@@NeetCodeIO I usually code in languages that don't have that method built-in, so if I were tasked with writing linear search in Java, it wouldn't occur to me to see if a built-in function with such functionality exists.

    • @CrabGuyy
      @CrabGuyy 5 місяців тому +54

      @@LandoKalrissianhe was being sarcastic, you stated the obvious missing the point of the video, so he prompted you with a equally useless comment. No hate, just explaining

    • @ecchioni
      @ecchioni 5 місяців тому +3

      Same reason why C# uses quicksort and insertion sort combo as its default sort.

    • @TacoMaster07
      @TacoMaster07 5 місяців тому

      @@CrabGuyy cache locality and branch predictability effects on different DS and algorithm ordinance is obvious? Dumbass.

  • @halfjainam
    @halfjainam 5 місяців тому +88

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

    • @someoneontheweb4515
      @someoneontheweb4515 5 місяців тому

      its not that big of a deal lmao

    • @rockdude1122
      @rockdude1122 5 місяців тому +2

      @@someoneontheweb4515 most people watching this video or just programmers in general have not done enough leetcode problems to remember the exact leetcode problem by just looking at 4 lines of code so its pretty impressive.

  • @GnomeEU
    @GnomeEU 5 місяців тому +223

    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!

    • @JosephGleespen
      @JosephGleespen 5 місяців тому +2

      It's a leetcode problem bro, that's what they are like

    • @mycommentmyopinion
      @mycommentmyopinion 5 місяців тому +14

      @@JosephGleespen Literally not the point.

    • @NeetCodeIO
      @NeetCodeIO  5 місяців тому +77

      i agree, even if you needed binary search you would use the built in one. Even i made a mistake in mine (l + r can lead to overflow).
      Best to rely on std libraries, even in the video why didnt he just use the built in linear scan of ArrayLists.

    • @QuanNguyen-og6pq
      @QuanNguyen-og6pq 5 місяців тому +14

      yup. Bad sql, bad joins has caused more slowness than any search problems I've seen.

    • @talareese580
      @talareese580 5 місяців тому +2

      I had to use binary search for a procedural level generation component in my game. I had to randomly choose an asset to spawn on a grid. But each asset had an associated percentage chance of spawning. So yeah.

  • @LukeDrumm
    @LukeDrumm 5 місяців тому +87

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

    • @elijahbuscho7715
      @elijahbuscho7715 5 місяців тому +25

      This is why I use PHP and throw performance out the window

    • @niggacockball7995
      @niggacockball7995 5 місяців тому

      @@elijahbuscho7715 unironically based, only old hags with shitpads from 2001 complain about performance like bruv just get a new pc its not that hard

    • @TehIdiotOne
      @TehIdiotOne 5 місяців тому

      @@elijahbuscho7715 I do Python

  • @shobhandash8720
    @shobhandash8720 5 місяців тому +72

    the bully: good, now do this in O(1)

    • @sharpfang
      @sharpfang 5 місяців тому

      ret=-1;
      for (i=0; i

  • @444limm
    @444limm 5 місяців тому +11

    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 in rust so Some(value) if the value is present and None if the index is out of bound

  • @n_x1891
    @n_x1891 5 місяців тому +46

    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 😂

  • @NeetCodeIO
    @NeetCodeIO  5 місяців тому +39

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

    • @mnaresh3382
      @mnaresh3382 5 місяців тому +23

      Do you mean the Microsoft surface laptop?

    • @NeetCodeIO
      @NeetCodeIO  5 місяців тому +42

      I'm tempted to delete your comment and edit mine...

    • @abdallaalhag4425
      @abdallaalhag4425 5 місяців тому +8

      LMAOO
      @@NeetCodeIO

    • @pengie_
      @pengie_ 5 місяців тому +8

      I run that same laptop but it's got linux running on it, had to put a sticker of my distro on it so people didnt think i run windows

    • @jonathanng7141
      @jonathanng7141 5 місяців тому

      What is wrong with Microsoft surface laptop?

  • @jonathanng7141
    @jonathanng7141 5 місяців тому +1

    I just learnt sorting this week and this video was perfect in helping me understand how the code is implemented!

  • @mukeshrawat1304
    @mukeshrawat1304 5 місяців тому +3

    Guess what?! I landed on Neetcode's YT channel while doing a brute force linear search on UA-cam. Definitely worth it ❤😊

  • @mycommentmyopinion
    @mycommentmyopinion 5 місяців тому +8

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

  • @vinayemani4105
    @vinayemani4105 5 місяців тому +9

    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.

  • @GMDeatHSoul
    @GMDeatHSoul 5 місяців тому +3

    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?

  • @connormc711
    @connormc711 5 місяців тому +3

    Wow. I have never seen someone with that close of an approximation to real skills

  • @ishanbajpai6940
    @ishanbajpai6940 5 місяців тому +30

    Silicon Valley, baby!!!

  • @sunnyyasser5625
    @sunnyyasser5625 5 місяців тому +11

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

    • @julioflores1849
      @julioflores1849 5 місяців тому

      I’m pretty sure it is to be sorted and the linked list needs to have a total node count

    • @Schnorzel1337
      @Schnorzel1337 5 місяців тому +1

      You basicly run past nodes not looking at their value. So you can not effectively do binary search on a linked list.

    • @matthewgraham790
      @matthewgraham790 5 місяців тому

      you still need to look at their 'next' pointer so by omitting looking at the value and comparing, you are still only diving the time by roughly 3, which although good, is still O(n) not O(ln n)@@Schnorzel1337

    • @TehIdiotOne
      @TehIdiotOne 5 місяців тому

      It's not a linked list, where'd you get that idea?
      FYI dynamic arrays are called ArrayLists in Java.

  • @TacoMaster07
    @TacoMaster07 5 місяців тому +12

    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.

  • @romanivanov6183
    @romanivanov6183 5 місяців тому +23

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

    • @NeetCodeIO
      @NeetCodeIO  5 місяців тому +43

      🤦i've dishonored my entire family

    • @oussamabennasr4936
      @oussamabennasr4936 5 місяців тому +13

      m = l + (r-l)/2

    • @blasttrash
      @blasttrash 5 місяців тому +2

      Correct me if I am wrong, but this issue doesnt exist in python right? Only in C, Java, C++ I guess coz of how ints are handled? If thats the case, it might explain why a python dev would not think of this. Also in Java, we have to be careful while writing comparators with integers(especially with heap based questions like top k etc). If we do a - b instead of Integer.compare(a, b) we will have similar issues.

    • @se4geniuses
      @se4geniuses 5 місяців тому +3

      @romanivanov True, but if you're iterating over more than 2^((sizeof(int) * 8) - 1) / 2 elements, you have bigger concerns to deal with.

    • @TehIdiotOne
      @TehIdiotOne 5 місяців тому

      @@se4geniuses You do, but it's not entirely unheard of

  • @pencilcheck
    @pencilcheck 5 місяців тому +2

    Just nit picking the naming of this title. Brute Force usually implied trying all possible solutions in a solution space. Those terms usually applied in optimization problems. Search in a 1d array isn't an optimization problem.

  • @ofbaran
    @ofbaran 5 місяців тому +3

    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
      @ofbaran 5 місяців тому +2

      Note: apparently I was wrong, Java implementation of .indexOf() is also linear search! In large samples a binary on a sorted array would be faster

    • @ofbaran
      @ofbaran 5 місяців тому +1

      The linear search is still useful if the array is unsorted, I'm sorry.

  • @justADeni
    @justADeni 5 місяців тому +1

    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.

  • @technophile_
    @technophile_ 5 місяців тому +5

    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.

  • @yashgangrade5460
    @yashgangrade5460 5 місяців тому

    Even though I've seen this before, watching it again with Neetcode makes it even funnier.

  • @69k_gold
    @69k_gold 5 місяців тому +2

    Wouldn't this be a massive code duplication issue? He's reinventing the wheel

  • @SuperMaDBrothers
    @SuperMaDBrothers 5 місяців тому +15

    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

    • @234lk
      @234lk 5 місяців тому +3

      Do you really think anyone would watch the show if they acted like software engineers?

    • @SuperMaDBrothers
      @SuperMaDBrothers 5 місяців тому +6

      @@234lk you really wanna watch a bunch of people act like brainless zombies? I guess that's what modern tv has become, let me just watch my character act in the way i want them to act. That is SO what jim and pam would do! LOVE ittttt!

    • @mycommentmyopinion
      @mycommentmyopinion 5 місяців тому +1

      I doubt it's made to be realistic lol, nobody would want to watch a realistic version

    • @anon_y_mousse
      @anon_y_mousse 5 місяців тому

      @@SuperMaDBrothers No, it's definitely a mistake, because there is a function to perform the search for you on a sorted array in every major programming language, even Java.

  •  5 місяців тому +2

    NitPick : In java you need a method to get a value from a list, not an array.

  • @Sharmav03
    @Sharmav03 5 місяців тому +1

    Bro pulled the question number out of his ass and got it right lmao!

  • @tungpho2132
    @tungpho2132 5 місяців тому +1

    Wow, actually rarely to see someone beat 100% of runtime 😮

  • @lmao4982
    @lmao4982 5 місяців тому +2

    you don't need a method to access array members in java, it has c-style syntax for that. these are lists.
    edit: ah you just did it

  • @AzidHouse
    @AzidHouse 5 місяців тому

    Why are you assuming that sortedList is just an array of integers? In Java, simple arrays don't have methods. You have to use [index] as usual to retrieve an item. On the other hand you cannot use < > operators for comparison between two arbitrary objects. And clearly sortedList is an ordered objects container. The proof is that here is used the equals method. So, what is the solution in that case? I'm truly interested, I saw many answers that address the problem without taking into consideration those aspects.

  • @asandax6
    @asandax6 5 місяців тому +2

    Not gonna lie when I write code I always write whatever pops in my head. I optmise it latter if I need to. The reason I do this is because I sometimes get side teacked into optimizing a single piece of code and by thw the time I realize I have wasted a lot of time on it. So better make it work then improve once it works.

  • @EudaderurScheiss
    @EudaderurScheiss 5 місяців тому

    i actually like the first solution more. it is standard pattern and you see what it does in a second. the l+r stuff is nice to have for high performance areas. but i dont understand leetcode. if i want to program or have it hard, i start game dev and waste time there

  • @rahuldwivedi4758
    @rahuldwivedi4758 5 місяців тому +1

    Which show is that?

  • @chandrap8391
    @chandrap8391 5 місяців тому +1

    The current generation CPU / GPUs process what ever junk we write inside a loop in a matter of no time. For 90% of Application Software the current Processors just chew any loop throwed at them before we notice it unless we have millions of rows in memory, which is not the case in 90% of the work.

  • @dracsharp
    @dracsharp 5 місяців тому +4

    From a business perspective and assuming you are building an MVP or a possible feature, the fastest to add solution is the right solution.

    • @xavier7769
      @xavier7769 5 місяців тому +3

      well bin search is fast to add he did it in like 2 mins

    • @mycommentmyopinion
      @mycommentmyopinion 5 місяців тому

      @@xavier7769 With a bug that could cost money and time to debug :D

    • @def__init
      @def__init 5 місяців тому

      Skill issue

  • @sprytnychomik
    @sprytnychomik 5 місяців тому +5

    Not sure that binary search would be so much better on a sorted (assuming linked) *list*, though.

    • @ValerieLoveTV
      @ValerieLoveTV 5 місяців тому +4

      Linked lists aren't accessible by index.

    • @TragicGFuel
      @TragicGFuel 5 місяців тому +3

      What kinda indexed linked lists are you playing around with?

    • @sprytnychomik
      @sprytnychomik 5 місяців тому +1

      @@ValerieLoveTVThis one apparently is.

    • @isodoubIet
      @isodoubIet 5 місяців тому +1

      @@ValerieLoveTV They can be if you write the api to do it. In Haskell for example they are.

  • @fromjavatohaskell909
    @fromjavatohaskell909 5 місяців тому +7

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

  • @ballakobe24
    @ballakobe24 5 місяців тому

    I also watched Silicon Valley for the code snippets.

  • @HighRankingBantam
    @HighRankingBantam 4 місяці тому

    What site did you used to do that?

  • @Dom-zy1qy
    @Dom-zy1qy 5 місяців тому +5

    This dude writes binary search like I breathe.

    • @edwardmitchell6581
      @edwardmitchell6581 5 місяців тому +1

      It's basically his full time job.

    • @ceciljoel9577
      @ceciljoel9577 5 місяців тому

      For seniors those algorithms for really that easy

  • @ChrisBakare
    @ChrisBakare 5 місяців тому +2

    High school never ends

  • @groot3271
    @groot3271 5 місяців тому +1

    Which video is that. Can someone share the link??

    • @SashaCianuro
      @SashaCianuro 5 місяців тому +1

      TV series Silicon valley

  • @Mankind5490
    @Mankind5490 5 місяців тому

    Bro really knew the LeetCode Number lmfao

  • @rinat2160
    @rinat2160 5 місяців тому +3

    Code in the show mentioned a list, not an array. You can't really do a binary search in a list unless you preprocess it first. But then its not just a list anymore.
    The joke was that the code in the snippet tries to get nth element from a list N times, so the overall complexity is O(N^2).

  • @Terrados1337
    @Terrados1337 5 місяців тому

    Back when I learned about search algorithms in school I was amazed. So much performance!
    Now that I have to handle actual data I rarely get to us any. Since data is complete diarrhea 99% of the time might as well map it. Too much memory usage? Download more RAM, duh!

  • @CallousCoder
    @CallousCoder 5 місяців тому

    Memory used 45MB?!?! I used to run a whole fucking file server with 32MB with a 100 clients attached.
    Also this isn't that trivia depending on the size of the list. As getting the length and dividing it and then doing the branch logic may well be slower on a list with a certain amount of entries (depending what also fits into the cpu cache).

  • @JaredT
    @JaredT 5 місяців тому +18

    This channel has potential to hit a million subs 🚀

    • @NeetCodeIO
      @NeetCodeIO  5 місяців тому +17

      Now that i think of it, i should really start uploading on the main channel again. I need to hit one milli before the end of the year 😤😤😤

    • @upsidedownChad
      @upsidedownChad 5 місяців тому +3

      ​@@NeetCodeIO I'll watch every video you post on my phone, computer and tv at the same time

  • @sonicfind
    @sonicfind 5 місяців тому

    They get the value at an index... *before* checking if the index is valid?
    Imma just use that with an empty list. That should be fun.

  • @nehadyounis
    @nehadyounis 5 місяців тому

    bro said "this is leetcode 704" and it was actually leetcode 704

  • @davidr.603
    @davidr.603 5 місяців тому

    So you just split the list in the half, and then search the right half. Why dont you split it multiple times, for a small list like in the example it might not be viable but for an even bigger list it for sure would be. Or am i thinking wrong here

    • @arjundureja
      @arjundureja 5 місяців тому +3

      It's a loop. The list is constantly being split until the target is found or the left pointer is greater than the right pointer

    • @davidr.603
      @davidr.603 5 місяців тому

      @@arjundureja gotcha, thank you for explaining

  • @whileforloops5671
    @whileforloops5671 5 місяців тому

    post more videos like this

  • @Cammymoop
    @Cammymoop 5 місяців тому

    I've never written a binary search algorithm in my life, I always know what the index is anyway

  • @asagiai4965
    @asagiai4965 5 місяців тому

    To be fair he might not have known it or forgot about it.

  • @brycejohansen7114
    @brycejohansen7114 2 місяці тому

    Well at least he didn't do a bogosort.

  • @user-gh4lv2ub2j
    @user-gh4lv2ub2j 5 місяців тому

    it's absolutely readable code; if you know C XD

  • @tmerb
    @tmerb 5 місяців тому

    "to turn up the difficulty lets do it in java" 🤣

  • @user-gh4lv2ub2j
    @user-gh4lv2ub2j 5 місяців тому

    "int index = 0;" -> how the hell is this a pointer?

  • @abdulmuqsit7568
    @abdulmuqsit7568 5 місяців тому

    Who do I get to be as good as you at leetcode bro?

  • @unixpro1970
    @unixpro1970 5 місяців тому

    Silicon Valley was a popular TV show, but this is ridiculous and uncalled for. He should have stood up for himself and left, if they continued to act like this. Constructive criticism is one thing, but abuse should never be tolerated. They acted like a bunch of clowns 🤡

  • @xstrngr
    @xstrngr 5 місяців тому

    from bisect import bisect_left (*ducks)

  • @sergrojGrayFace
    @sergrojGrayFace 5 місяців тому

    Also, never write binary search for a simple list, because you'll probably find a standard implementation for it in any language.

  • @chemaalonso7931
    @chemaalonso7931 5 місяців тому

    Who need brackets? Is an ArrayList and is SO MUCH DIFFERENT from an Array, in JAVA you DONT need a fucking method to get an element.

  • @def__init
    @def__init 5 місяців тому

    who tf writes while statements with no body 💀

  • @parryhotter9333
    @parryhotter9333 5 місяців тому +5

    why do you call an index a pointer? they are two very different things

    • @groff8657
      @groff8657 5 місяців тому +2

      He meant value pointers in DSA not memory pointers in C++.

    • @parryhotter9333
      @parryhotter9333 5 місяців тому +2

      @@groff8657 Since the programming language in question is Java, he most certainly should have said "index" because the .get method on a list takes an integer to index into the list and not a pointer.
      A pointer is not even a defined datatype in Java so using this keyword in this context is not even appropriate. If you really want to be fringe, then you might argue that a variable reference to an object is a "pointer", however this is incorrect as Java never actually provides direct references to objects with an address (which is the definition of a pointer to an object), but rather to a proxy that keeps track of the object. An apt name for a strategy that encapsulates this behavior is therefore "pass-by-proxy".
      In any case, a "value pointer" is not even a recognized term in DSA, so why even bring this up?
      edit: this is not to discredit NeetCode in any way, but as a channel that teaches and talks about programming, he should be precise in his wording and explanation. With that said, it is a nice video and not all that serious.

  • @BulbaWarrior
    @BulbaWarrior 5 місяців тому

    The funniest part is that binary search is not that big of improvement on a (linked) list

  • @hendrikmartina3552
    @hendrikmartina3552 5 місяців тому

    The guy have my same name. But I will never write that monstrosity

  • @bigbigdog
    @bigbigdog 5 місяців тому +2

    If I am not mistaken that while loop does nothing. Notice the semi-colon at the end of line 114. That closed the while loop.

    • @anon_y_mousse
      @anon_y_mousse 5 місяців тому +1

      Notice the ++index in the condition header? Yeah, that's the loop.

    • @asagiai4965
      @asagiai4965 5 місяців тому +2

      Technically it does something. It is increasing the index. The index which the item is on will exit the loop thus giving the answer

    • @Kurushimi1729
      @Kurushimi1729 5 місяців тому

      It's a funny way to write a loop (at least I haven't seen it before) but it looks valid. I guess they were trying to be terse.

    • @bigbigdog
      @bigbigdog 5 місяців тому

      @@asagiai4965 "Technically"

    • @bigbigdog
      @bigbigdog 5 місяців тому +1

      ​@@anon_y_mousse no that's what cause the loop to end. The loop itself still does nothing... other than increasing the index.

  • @giantbush4258
    @giantbush4258 5 місяців тому

    If N is small you can get away with being lazy and do a linear vs logN search. Say searching through a list of countries or states.😂

  • @LeandroAndrus-fn4pt
    @LeandroAndrus-fn4pt 5 місяців тому

    This video sounds like you could’ve wrote this code…

  • @akialter
    @akialter 5 місяців тому +3

    You’ll be surprised how many average dev cant write a bug free binary search

    • @mycommentmyopinion
      @mycommentmyopinion 5 місяців тому +4

      Tbf I haven't had a case where I had to implement binary search myself and I think that goes for most devs

    • @anon_y_mousse
      @anon_y_mousse 5 місяців тому +3

      @@mycommentmyopinion As an exercise, write your own libc. Go back and do it every 5 to 10 years.

    • @JosephGleespen
      @JosephGleespen 5 місяців тому +1

      ​@@mycommentmyopinionlmfao it's not about how much it comes up at work, it's a test, are you all being purposely dense about this? It is an EASY way for companies to TEST if they want to hire you. Jfc.

    • @mycommentmyopinion
      @mycommentmyopinion 5 місяців тому +1

      @@anon_y_mousse Good idea, gonna try that

    • @blasttrash
      @blasttrash 5 місяців тому

      Well even oracle jdk apparently had a bug in binary search for many years. And JVM is said to be one of the most optimized software written. So even the geniuses at Oracle made binary search mistakes :P

  • @QuanNguyen-og6pq
    @QuanNguyen-og6pq 5 місяців тому +2

    It's O(n), it's not the slowest subroutine in history (That would be my response xD)

  • @user-oe2bf4rz3s
    @user-oe2bf4rz3s 5 місяців тому

    ✍👍

  • @TheKapei22
    @TheKapei22 5 місяців тому +2

    Most people that make to big tech are nerds. Most of the time a nerd becomes a nerd because of social pressure and abuse from parents (endless comparisons, pushing kid to study more). Btw this is also a result of parents growing up poor and realizing the need to study more and more to make more money. If not parents, grandparents. Then these nerds also get subjected to peer abuse (working hard stereotype).
    I was a smart kid in HS. But quickly realized if I get best grades, this would lead to peer bullying (nerd jokes). So I avoided studying harder.
    In the end these people have mental voids inside to fill. This comes out as abusing other people.

    • @EudaderurScheiss
      @EudaderurScheiss 5 місяців тому

      nerds are mostly people that are very interested in that stuff and enjoy solving problems. no nerd i know is a nerd because of peer pressure or pressure from their parents, its the absolute opposite. they love it because its fun.
      but they are made fun of, because they often have an higher iq and therefore have it harder to interact with normal people. if your brain runs at 3x speed of others to intake and process information you have a hard time to interact with mostly affect driven people. its like being belonging to a different species

  • @CodingMachine007
    @CodingMachine007 5 місяців тому

    Like if you tried to increase volume through UA-cam's volume icon on video 🤣

  • @OnFireByte
    @OnFireByte 5 місяців тому

    definitely one of the worst way to write linear search.

  • @Namynnuz
    @Namynnuz 5 місяців тому

    What are you actually doing, if you used to write binary search? Who would write it at most twice in a lifetime?..

    • @danddietz
      @danddietz 5 місяців тому

      Yeah, I was wondering the same thing. Don’t most standard libraries have this implemented? Just like the actual sorting of the list/array?

  • @unendingessence4001
    @unendingessence4001 5 місяців тому

    i dont understand what the hell all of this means but okay

  • @jaywin5373
    @jaywin5373 5 місяців тому

    In the real-world interview, you make a stupid mistake, and they will make you dumber than usual.

  • @div_tm
    @div_tm 5 місяців тому +1

    This only matters if the code segment is performance critical, otherwise probably unnecessary to do a binary search. It's better to optimize the critical parts and leave the other parts as simple as possible. Anyway, nothing to laugh at, really.

    • @edthelazyboy
      @edthelazyboy 5 місяців тому

      I would also agree. The firmware code base I worked on for has various non performance command handlers for calling functions based on opcode used linear search. They are straightforward to read and historically functioned reliably. Changes are often made to the opcode / function pointer table so the table isn't guaranteed to be sorted anyways if someone accidentally adds a table entry out of order based on the opcode. Sometimes, better readability and maintainability is more important.

  • @bsdetector6908
    @bsdetector6908 5 місяців тому +2

    I'm a senior developer and I do a lot of code reviews. I can definitely tell you if I saw code like this in a pull request I'd wonder about the dev's competency.
    I would accept code like this from a junior dev (but I wouldn't let them merge it - they'd have to change the code) but if anyone with more than 2 years experience submitted this .... either they go or I go

  • @deathbombs
    @deathbombs 5 місяців тому +1

    Kumail!

  • @cguser
    @cguser 5 місяців тому

    test

  • @guruware8612
    @guruware8612 5 місяців тому

    By calling "int index=0" a pointer you are already done with a interview.
    Who needs brackets? - bye, next candidate.

    • @NeetCodeIO
      @NeetCodeIO  5 місяців тому

      Pointer is a very generic term in programming lol, google it if you don't believe me