Mock Google Coding Interview with a Meta Intern

Поділитися
Вставка
  • Опубліковано 3 лют 2025

КОМЕНТАРІ • 894

  • @NeetCode
    @NeetCode  2 роки тому +127

    🚀 neetcode.io/ - Get lifetime access to all current & future courses I create!
    Btw this is the question I asked: leetcode.com/problems/insert-delete-getrandom-o1/
    We actually solved it on the channel here: ua-cam.com/video/j4KwhBziOpg/v-deo.html

    • @alisonoz7219
      @alisonoz7219 2 роки тому +2

      Yeah I'd like to see that 🤩

    • @zesanurrahman6778
      @zesanurrahman6778 2 роки тому

      I became homeless. I am depressed

    • @slayerzerg
      @slayerzerg 2 роки тому

      yeees

    • @smtp_yurzx
      @smtp_yurzx 2 роки тому

      It seems only fair and right with the world. I mean if you prefer balance in the universe rather than chaos.

    • @ralph_d_youtuber8298
      @ralph_d_youtuber8298 2 роки тому +1

      Hi, sorry isn't duplicate problems easily solved with sets, as this doesn't allow duplicates, and it's call is already random.

  • @Dulandor
    @Dulandor 10 місяців тому +1857

    "If there is a problem, just throw a hashmap at it."
    - someone really smart

    • @subhrajyotisen7218
      @subhrajyotisen7218 10 місяців тому +19

      Funny how true this is

    • @jersynumber18
      @jersynumber18 9 місяців тому +16

      @@subhrajyotisen7218 why not Hashset here ? until follow up question

    • @subhrajyotisen7218
      @subhrajyotisen7218 9 місяців тому

      @@jersynumber18the code in this interview seems to be more pseudo code. When writing actual code, they will mostly have to to use hashset since Set is usually an interface in many languages and HashSet is one of the implementations

    • @nile7999
      @nile7999 9 місяців тому

      @@jersynumber18 you need to store the index as the value.

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

      Works all the time

  • @BTC500k
    @BTC500k 2 роки тому +2063

    “In your real interviews, do you talk the same way..?” LMAO that is the question I wanted to ask lol

    • @pinecedar180
      @pinecedar180 Рік тому +87

      It was obviously a frank discussion between friends

    • @parvscripter
      @parvscripter 10 місяців тому +54

      @@pinecedar180 but you can be pretty frank just don't be unprofessional

    • @decomush
      @decomush 9 місяців тому +61

      I'm 5 min into the video and I wanted to ask that

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

      ​@decomush do you think you're superior for being socially inept and not realizing these are 2 friends ?

    • @decomush
      @decomush 7 місяців тому +16

      @@WoWUndad not really, just a fair question to help out the guy

  • @hariharanm9930
    @hariharanm9930 2 роки тому +1294

    Hey Neetcode! I got the exact same question on my Adobe interview two days ago. Luckily I have been practicing from your collection of questions last few months and never missed any of your videos. I bagged my offer today!! You have literally made this happen for me. Can’t thank you enough for this day!

    • @onkarsingh-vu1ds
      @onkarsingh-vu1ds 2 роки тому +19

      Hi, is adobe allowing remote work?

    • @OkvEdit
      @OkvEdit 2 роки тому +36

      Congrats ma boi

    • @usa5450
      @usa5450 2 роки тому

      Congrats nigg*

    • @dv-89
      @dv-89 Рік тому +8

      what collection of questions you are talking about? Neetcode 150?

    • @paultvshow
      @paultvshow 11 місяців тому +13

      Hey man. I have been preparing for coding interviews for a month now. I am a self taught coder who is passionate about coding especially in AI and machine learning fields. I have just started coding for 3 months with hands on projects of over 50+ as I have quit my previous job and dedicated my full time learning coding. During the past weeks, I spent at least 4-5 hours a day on Leetcode and I have completed almost 100 problems. Now then I have started watching coding interview videos, and I feel that problems in most mock interviews seem a little too easy. So I just wanted to know from people like you who have already experienced real interviews that how difficult are there real problems?

  • @free-palestine000
    @free-palestine000 2 роки тому +1437

    please record more of these google mock interviews!! this questions seem so easy initially, but watching how frypan is talking aloud and saying his thought process makes me realize how the little details he says is actually valuable to you (neet) as the interviewer. now i realize why i failed my interviews so much

    • @danielbrown7534
      @danielbrown7534 2 роки тому +4

      Watch this i was thinking maybe we could store in an array..but wont store in array initially..we would then use a function to check the array if the value was already store there.. if yes then use the value position to store the new figure.. if no then use the new value as storage.. I would also use a function to get a random number using the array limitation then use that random number to return a value from set.

    • @ahsanmurtaza6185
      @ahsanmurtaza6185 2 роки тому +13

      @@danielbrown7534 That wouldn't meet the time complexity requirements.

    • @stefannita3439
      @stefannita3439 Рік тому

      @@danielbrown7534 searching in an array is O(n). Unless the array is sorted, in which case you can use binary search and it becomes O(logn). But to be able to always search in O(logn) you have to maintain the sorted order of the array at all times, which means your insertion becomes O(n) (find the correct index to insert at to maintain sorted order: O(logn), insert and then shift all of the elements to the right of it: O(n)) and your removal is now also O(n) (typical array removal).
      The point of this question is to kind of juggle all of these limitations. Every time you choose a data structure to optimize one of the operations, something else becomes more expensive. Nothing is free. This is why the trick is to use different data structures simultaneously, each good at different operations, and figure out how to make them work together to create an interface where all three of the exposed operations are O(1). But even this isn't free, as you're now basically doubling the memory you use (still O(n) space tho).

  • @nikhil_a01
    @nikhil_a01 2 роки тому +1331

    I find it funny that when he googled for how to get an arbitrary element from a set, he actually found Java code, and pasted it into his Python solution. And NeetCode is just like "great".

    • @malikau917
      @malikau917 Рік тому +10

      😂

    • @user-lt6hz7jh2p
      @user-lt6hz7jh2p Рік тому +1

      I 😂😂😂

    • @NotNazuh
      @NotNazuh Рік тому +2

      😂😂😂😂😂😂😂😂😂

    • @tahashakeel
      @tahashakeel 10 місяців тому +3

      I didn't notice that, can anyone paste the timestamp. I watched the video twice still didn't see it

    • @AbhishekKumar-cl6ou
      @AbhishekKumar-cl6ou 10 місяців тому

      39:19@@tahashakeel

  • @tusharvyavahare9229
    @tusharvyavahare9229 2 роки тому +776

    for python folks, removing an item from set, which isn't in the set , using remove() method will result in error, so use discard() method.

    • @danielsank2286
      @danielsank2286 2 роки тому +94

      Just use pop

    • @yatintyagi4366
      @yatintyagi4366 Рік тому +6

      or just use an if statement

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

      @@yatintyagi4366 wouldn't the if statement be more clear since the value isn't in the set to begin with? Thus if changed in the future... it'll still run correctly?

    • @sandeepreddy1286
      @sandeepreddy1286 9 місяців тому

      Agree smart move

    • @bit-learn
      @bit-learn 8 місяців тому

      @@danielsank2286 pop removes a random value from the set, not the required one

  • @dacattilearnsenglish3141
    @dacattilearnsenglish3141 Рік тому +41

    There were 4 people in my coding interview a few months ago. They were quite friendly with me, though. I had to code C++ in MS Word, which was a pain the neck. Even the easiest questions become hard because of tension. In addition to that, time flies when you are under pressure because you are trying to come up with an answer in your head and trying to word it properly.

  • @Protocoding
    @Protocoding 2 роки тому +193

    Things I'm starting to realize every developer needs to do during an interview. Ask tons of questions before even thinking about coding, even if they seem obvious. If the easiest way to think of a question is in one-time complexity odds are they are hinting at the complexity they want in the description of the question.

    • @MichaelButlerC
      @MichaelButlerC Рік тому +19

      I just hate to ask questions for the sake of asking questions though...

    • @eesnehhil
      @eesnehhil Рік тому

      @@MichaelButlerC frfrfr

    • @AnimeZone247
      @AnimeZone247 8 місяців тому

      @@MichaelButlerCyou’re going to have to do that during the actual job

  • @SankarshanGhosh
    @SankarshanGhosh 2 роки тому +108

    This is the first time I watched a 40 minute video. Real fun, we want more of these!

  • @willboler830
    @willboler830 2 роки тому +178

    Gah, what people watching this might be missing out on is the anxiety, and the difficulty between coding and talking through the code. I sat here correcting him as he went, but also remembered how much I stumbled over trivial stuff. It's so nerve racking.

    • @asagiai4965
      @asagiai4965 10 місяців тому +1

      True, IMHO I think he should ask all the possible questions. To ease the doubt.

  • @krovvidisupraja6822
    @krovvidisupraja6822 2 роки тому +107

    Thanks so much @NeetCode for doing this. I think this video is pretty realistic (except for the way @FryingPan talks 😂) compared to the other mock interview videos online! Helped me relate a lot being an interviewee. Looking forward to more such videos!! Keep inspiring with your good work 😃

  • @Neilblaze
    @Neilblaze 2 роки тому +104

    Been watching Mock interview sessions for a long time, but this is by far the most enjoyable session for my all time :)

  • @Suraj-tz3oq
    @Suraj-tz3oq Рік тому +158

    "i have ocd and this is pissing me off"
    My interviewer: get tf out then 😊

  • @atharvagupta9355
    @atharvagupta9355 2 роки тому +28

    This interview made me realize that I can do it too. Thanks, Neetcode

  • @yitongxie6574
    @yitongxie6574 2 роки тому +26

    the last part you ask 'do you talk like this in real interview?' and then 'nothing' really make me laugh

  • @rajingale5776
    @rajingale5776 2 роки тому +67

    The collab we waiting for..🔥
    The only 2 coding channels i subscribed and getting that collab is awesome..

  • @jasonswift7468
    @jasonswift7468 2 роки тому +23

    This is a really inspring mock interview. Learn a lot from this standard mock interview. Please upload more similar interviews including system design mock interview.

  • @Ripred0219
    @Ripred0219 2 роки тому +29

    The snarky comments while Neetcode remained mute was hilarious

  • @LeSpaceCroissant
    @LeSpaceCroissant 8 місяців тому +9

    My man was coding in Python and searched how to get the first element of a set in Java. Genius. And he said it so confidently too: "I got it sir! I got it!" 39:25 😂
    It's "next(iter(mySet))" by the way.
    And thank you for the video, it was really nice!

  • @marspark6351
    @marspark6351 2 роки тому +152

    Theres something neither of you caught. When you remove elements from the set that keeps track of indices and when there's only one element in the set, you are left with an empty set. What you want is to get rid of the map entry altogether. So you should check if it's the last element, and if it is, del that entry.
    Also, he mentions changing to a set instead of an array because when he chose the array first, he was using the first index and then he probably thought "wait.. now if I delete the first index I have to shift all the remaining ones to the left". Well actually you can simply use the last one instead of the first by using "pop", and so you can still use the array

    • @christiancepeda5457
      @christiancepeda5457 2 роки тому +3

      excellent observation

    • @ProfessorQuality
      @ProfessorQuality Рік тому +4

      what if you want to remove the number first in the list, you can't use pop() instead?

    • @xingzheli7431
      @xingzheli7431 Рік тому +2

      It's remove by value, so it's worst-case linear time for an array.

    • @Biggyweezer69
      @Biggyweezer69 Рік тому

      @@massalkhii This actually isn't true. since we are only ever pushing values into the values array, the index of the last value in the value array will always be the last index in that values index array. This stays true whether there are duplicate last values or not. Using a set here isn't better really.

    • @massalkhii
      @massalkhii Рік тому

      ​@@Biggyweezer69 I realized I was digging deep, while even the obvious case of having a duplicate of the last element, it raises an error (in the final code of the guy in the video)

  • @brainesteven6365
    @brainesteven6365 9 місяців тому

    in the 30:28, the follow up question is to allow array to store duplciate. The follow up seems to be simplified, in general, it may ask while allowing to store duplicate values, what is to make each number to has the same probility in getRandom(say 1,2,2,2,2,2,3), 1 and 2 and 3 has the same 1/3 probility to be returned.

  • @SanjanaSingh-mc6re
    @SanjanaSingh-mc6re 2 роки тому +33

    Can we get more interviews like this one? It was really helpful. Thanks!! 🙂

  • @supastazz
    @supastazz 2 роки тому +4

    That adding array to value for duplicate values was amazing, always had that doubt but I found the answer today. Thank you for the post

  • @axaxaxaxaxaxax33
    @axaxaxaxaxaxax33 2 роки тому +32

    the collab i didnt know i need 😂 frying pan is too funny lol. Great hint from Neetcode too, just enough to nudge him into revelation

  • @tedwoldeselassie5715
    @tedwoldeselassie5715 Рік тому +4

    I would implement the Get(bool random, Enum input) first, then when implementing the Insert, pass each iteration to Get() with random false. If it returns a value then dont insert it as its duplicate. To get random you jusst need to set random to true. Then the remove is straight forward.

  • @utsabkhakurel9742
    @utsabkhakurel9742 Рік тому +6

    In the follow-up, you could have just chosen the last element from the list to swap self.map[value][-1] and used pop() to remove it after the swap.

    • @yosup7563
      @yosup7563 9 місяців тому

      There is no indexing in sets so self.map[value][-1] wouldt work and then he also pasted some wrong java code in

  • @yehudacorsia3323
    @yehudacorsia3323 2 місяці тому +1

    Thank you, it was great!
    Just a heads-up, I’ve found a small bug. If you do the following:
    s = Store()
    s.insert(1)
    s.remove(1)
    s.remove(1)
    The issue arises because the check is only
    `if value not in self.map`
    but it should be
    `if len(self.map[value]) > 0`
    to correctly handle multiple removals.

  • @MrPkmonster
    @MrPkmonster 2 роки тому +13

    That's cool. I've learned a lot during the Mock test interview. Understand deeply the way the interviewer asked the candidate and the way of thinking to solve the problem.

  • @jonTheDon28
    @jonTheDon28 Рік тому +34

    None of my coding interviews for internships have been anywhere near this easy

    • @harryzhu
      @harryzhu Рік тому +6

      but the mock interviews from faang are - its a mock not a real assessment- its used to get a feel for the format and UMPIRE application

    • @rexibhazoboa7097
      @rexibhazoboa7097 3 місяці тому +9

      @@harryzhu Arent mocks meant to be harder than the potential interview? So you're more than prepared.

  • @applepine3172
    @applepine3172 8 місяців тому +9

    17:55 When he realized what's the right way, and you see the smile, that's why we love programming.
    That's why ones, who think "I want to be a programmer because it means I get a lot of money" always fail. Whoever loves this, feel fun when programming is always the one who reaches his goal.

    • @christosgran5486
      @christosgran5486 Місяць тому

      can you explain why moving it to the end of the array, before removing it, changes the complexity of the code?

    • @thepalerider1758
      @thepalerider1758 28 днів тому

      ​@@christosgran5486 I'm kinda of a newbie here but here is what I think that would be the answer to your question.
      An array is on going data structure meaning that it only moves forward. That means if we want to search again, we have to go through all the elements one at a time and this will take extra time when we're removing an element.
      By moving the element we want to remove to the end of the array, we can simply remove it without going through every element in that array like this:
      Remove Arr[length - 1];
      I think this is a good solution that will improve the complexity like he said.

  • @chrisrey2516
    @chrisrey2516 10 місяців тому +2

    i was able to come up with similar solution. I'm happy lol. I was thinking along with him

  • @jackli1924
    @jackli1924 Місяць тому

    It was really a pretty good coding mock interview. Amazing, thank you a million times Neet!

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

    @42:43 To make the code thread safe, you do NOT need to add any locks for the read operations, so get_random(self) function will not need thread safety, only the write operations (insert/remove) will need it

  • @YanaGupta_01
    @YanaGupta_01 Місяць тому +2

    Got same question in my Amazon SDE winter internship interview.

  • @jose6378
    @jose6378 2 роки тому +5

    Unironically got a very similar question for Amazon SDE position

  • @karanbhatia2834
    @karanbhatia2834 2 роки тому +4

    This was like actually really awesome. I felt like I was solving the problem with him!

  • @harryshi1
    @harryshi1 2 роки тому +7

    love the concept, if you need another person to mock interview I would be happy to do one. I am an ex Quant trader now studying for algo / CS jobs.

  • @atailihave4506
    @atailihave4506 2 роки тому

    Thanks!

    • @NeetCode
      @NeetCode  2 роки тому +1

      Thank you so much!!

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

    i'm not really sure about that but inserting in a hashmap, will, at some point, result in a reallocation of the elements, since under the hood you store the elements inside an array indexed using a hash function. Usually you allocate more space when you have the array half full or 3/4. A data structure with an array that has a little buffer and gets reallocated when half full will get you the same time complexity, i suppose.
    Also when deleting, yes, when you delete an element from the end of the array you don't need to push elements around to fill a void, but you still retain that memory. After some delete operations you would want to release that memory by realloc-ing everything in a smaller array and freeing the old memory.

  • @atalaramadhan9313
    @atalaramadhan9313 2 роки тому +4

    The collab I was waiting for years. You guys are prob my fav swe youtubers

  • @techhoseki
    @techhoseki 4 місяці тому +3

    By the way, his original solution was great.
    We could still use a set, to insert and remove in O(1). As for the get_random method, he should have used 'random.randint(0, len(self.values)-1)' to get a random index and then get it using self.values[index].

    • @devariss_fn
      @devariss_fn 4 місяці тому +2

      Exactly what I was thinking for my original design

  • @elanatar8940
    @elanatar8940 26 днів тому

    To get a random number using a set, I believe you can pop() a value and add() it back in after so it is a 2 0(1) solution 18:45.
    Please correct me if I am mistaken, I’m not an expert

  • @creamymain7867
    @creamymain7867 Рік тому

    Love the "Now let me ask you another question" at the beginning haha. Very inciteful video btw

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

    9:45
    Being someone that first learned about lists in C, removing and adding was truly something, seeing this makes me have high hopes in my future coding career lol.

  • @christianmorera4127
    @christianmorera4127 2 роки тому +5

    I love this, frying pan makes coding interviews fun

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

    There is an obvious bug when the value we are going to remove is equal to the last element in values list, in which case adding the index before removing will end up losing the index.

  • @FaberLSH
    @FaberLSH 6 місяців тому

    Awesome. I learned so much about how a coding interview looks like. Thank you!!

  • @chair_smesh
    @chair_smesh 2 роки тому +8

    You mentioned that you don’t actually use Google docs for coding interviews? What do you use a Google IDE? How do you draw out solutions on a Google online interview?

    • @SiddhantDubey
      @SiddhantDubey 2 роки тому +4

      it's not exactly "Google docs" but it's basically the same thing, just with syntax highlighting and no autocomplete (or there wasn't when I interviewed)

    • @t_regbs
      @t_regbs 2 роки тому +4

      yea its kind of a modified version of google docs (at least that's what it looked like) with syntax highlighting

  • @isaiahparadiso8044
    @isaiahparadiso8044 2 роки тому +29

    Pro tip to people interviewing. Don’t talk like this guy. Don’t swear. Don’t quiz the interviewer. Finding the optimal solution is a must, but they’re also deciding if they want to work with you. Some crude banter can give the wrong signal, and there’s zero advantage to you in risking it. Be polite. Don’t be cocky. Every grading rubric has score around cultural and team fit. Just FYI.

  • @chengyuanchang4000
    @chengyuanchang4000 2 роки тому +9

    The code in follow up has a bug...
    In the remove function, when the size of self.map[value] equals to zero, we need to delete the empty set like `del self.map[value]`.
    Otherwise, next remove call for same element will cause an error.

  • @SankHar4
    @SankHar4 2 роки тому +1

    Neet code Please do conduct whenever possible it helps the everyone a lot of Learning. Thank you so much...

  • @RaghavRathi-qb8fr
    @RaghavRathi-qb8fr Рік тому

    This is prolly the best channel out there for ds algos!!!

  • @varshasingh1299
    @varshasingh1299 2 роки тому +10

    Big fan of neetcode ❤️ just want to thank for all the amazing content you post in your channel... Thank you 🙏 love from India

  • @MikeKm-hd1ve
    @MikeKm-hd1ve 10 місяців тому

    Priceless video!! Thank you so much!!

  • @RvGeral
    @RvGeral День тому

    I'm pretty proud I could think of using the hashmap with the array right away. But I had the same doubt as him, how to get avoid the O(n) removing an item from the array an updating the index at every key in the hashmap

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

    Never thought interviews would be that funny, cool !

  • @negarvahid
    @negarvahid 2 роки тому +3

    Bro why didn't you upload this sooner I had my interview yesterday :,)

  • @salvadorortiz449
    @salvadorortiz449 2 роки тому +7

    Something important is the use of descriptive names for your variables, because in this case without any previous context you won’t figure out what’s the function of “map” or “values”variables.

    • @mannyb096
      @mannyb096 Рік тому +1

      thats actually a great point! I guess in this case what kind of variable names would you use? Bcuz i cant think of what to call them other than values either lol

    • @hydromaniac7117
      @hydromaniac7117 Рік тому

      @@mannyb096 removedInt

  • @YSTYG
    @YSTYG 2 роки тому +167

    I thought we were about to get a face reveal 😂

    • @NeetCode
      @NeetCode  2 роки тому +43

      Maybe on part 2... lol

    • @somakkamos
      @somakkamos 2 роки тому +11

      Seriously man..i so badly want to see neetcode.. in my mind he is like moriarty frm sherlock show... coz thats how brilliant neetcode is.😊😊😝

    • @josepha8415
      @josepha8415 2 роки тому +8

      @@NeetCode Is Techlead in the thumbnail

    • @joshthe10xengineer
      @joshthe10xengineer 2 роки тому +1

      Me too..neetcode, make it happen!

    • @skyhappy
      @skyhappy 2 роки тому +3

      Neetcode looks like an angel for sure

  • @andreainvernizzi8510
    @andreainvernizzi8510 2 роки тому +1

    So many headaches to end up in a cubicle Monday to Friday.
    May as well deploy this knowledge to develop independently and get all the benefits.

  • @denhoward6438
    @denhoward6438 2 роки тому

    Nice video, I can feel the pressure of the interviewee by his word and face

  • @5pellcast3r
    @5pellcast3r 2 роки тому +5

    The collab I didn't know I needed ..... 🙃

  • @paulofelipe2780
    @paulofelipe2780 9 місяців тому

    Another important question that could have been asked is the range of possible values to be inserted, it can influence a lot the final solution complexity!

  • @jagadeeshkumar7724
    @jagadeeshkumar7724 2 роки тому +38

    Frying pan is hilarious though he is not explicitly trying to make fun of the situation.

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

    I think for removal function, you can just use the insert function with a small update so it can be able to return the position of the already existing value, overwrite the value and put the last one in it, correct guys?

  • @AnoopSonawane-y1w
    @AnoopSonawane-y1w Місяць тому

    my semester exams are tomorrow and here im watching this at 4 am.Man we really are cooked

  • @saurabhgambhire-v4o
    @saurabhgambhire-v4o Рік тому +2

    Funniest, energetic interview I have ever seen , I want confidence like this😅🤣

  • @bit-learn
    @bit-learn 8 місяців тому

    please @NeetCode if your are watching .. so on the first part my approach was to solve everything through set as set gives everything like adding, remove with num and generating a random number from set (we can add it again on the next line) plus on the second part where duplicates are allowed .. we can change it to hashmap so that on removing if the values aren't zero we can just remove the iteration count of the numbers or pop the number otherwise when iteration count goes 0.
    need help in clarifying it .. thanks for experience though

  • @govindbanura3327
    @govindbanura3327 2 роки тому +26

    I feel that moment when you said "do you really talk like this in real interviews" and he replied "what's wrong with how I talk"
    Your reaction was "nothing" 🤣🤣 I felt that man 🤣🤣

    • @grmn3564
      @grmn3564 2 роки тому +2

      He should have been honest there!
      Judging from the comments he's kinda acting; but besides your ability to solve problems, it's also super important to be pleasant to work with. One can be funny and entertaining while staying humble and mindful.

    • @misterl8129
      @misterl8129 2 роки тому +1

      like we say in chile, "que cagon eres" she should tell him with no fear of hurting him lol

  • @木漏れ日-v9n
    @木漏れ日-v9n 3 місяці тому

    This is a great interview question. Easy to understand, lots of tradeoffs.

  • @MightyElemental
    @MightyElemental 9 місяців тому

    got my first interview on wednesday and this video equally relaxes and terrifies me 😅
    Trouble is I cannot think aloud. I can think, then explain, but that takes more time. Hopefully not an issue, but we shall see 🤞

  • @abhishekgarg8769
    @abhishekgarg8769 Рік тому +2

    Saw this Video yesterday, got random recommendation and today i got this question on leetcode daily challenge question, i was shocked about it but the explanation was so good i did the question in one go

  • @srinadhp
    @srinadhp 2 роки тому +1

    Invigorating! Great questions all around, even greater thoughts and solutions!

  • @sriharisrinivasan5108
    @sriharisrinivasan5108 Рік тому

    how did I get this recommended just before the daily leetcode question became this today

  • @koch9666
    @koch9666 2 роки тому +9

    Omg that was so fun I really enjoyed the vid and it's perfect too because I have a final round coding interview later this week! You guys should collab more often, that would be such good content!

  • @Silverne_Capricorne
    @Silverne_Capricorne 3 місяці тому +2

    Why not directly using a list, am I missing something?
    class ElementManager:
    def __init__(self):
    self.elements = []
    def add_element(self, element):
    if element in self.elements:
    return
    self.elements.append(element)
    def remove_element(self, element):
    try:
    self.elements.remove(element)
    except ValueError:
    print(f"Element '{element}' not found.")
    def get_random_element(self):
    if not self.elements:
    return None
    return random.choice(self.elements)

    • @Michael-ob7wz
      @Michael-ob7wz 3 місяці тому +1

      It’s because removing from a list is O(n) and the entire point was to make it O(1), that’s why he switched the elements and popped the last one

  • @cenchang3765
    @cenchang3765 Рік тому +1

    So funny. I am still struggling with leetcode by just finishing the first 200. And I did not have much interview experience. The video makes me feel like we are all human beings.

  • @cowaiicow8802
    @cowaiicow8802 2 роки тому +6

    I never thought i needed this collab until now...

    • @zweitekonto9654
      @zweitekonto9654 2 роки тому

      You never know what u need until its too late. Thats why ur broke.

  • @JoaoPereira-if5jk
    @JoaoPereira-if5jk 9 місяців тому +3

    Awesome video!
    Quick question:
    What's the point of changing the last item of the array to the value to be deleted if you're just going to pop it anyway? Can't we just remove that extra step?

    • @clu52
      @clu52 3 місяці тому

      Deleting from an array is not generally O(1). If you delete from the middle of the array, say at index i, you have to shift indexes i + 1, i + 2, ... etc. left one index which takes O(n) time.

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

    I've been working as a software developer and I have had to make use of a hash map exactly once in my life

  • @INDNICK
    @INDNICK 2 роки тому +1

    I like how he said using google docs is stupid and it pisses me off in an interview 😂

  • @ztrixx3280
    @ztrixx3280 Рік тому

    this was really informative and fun at the same time. thanks NeetCode.

  • @imbes64
    @imbes64 2 роки тому +2

    pretty decent easy-med level q to ask, will use in my own new hire interviews as it makes for good discussion!

  • @janni7439
    @janni7439 2 роки тому +5

    Those sort of questions are a little bit odd, because the "reduce complexity" always boils down to the data structure behind and there basically a lot of useful stuff was already invented, so you wouldnt hire someone, who can recreate such a structure from scratch, because that's totally not part of the daily business.

  • @elanatar8940
    @elanatar8940 26 днів тому

    25:18 missing self.values[index] = last_val
    I don’t believe he switched the two values correctly. He moved the needed value to the end and updated the set accordingly, but I don’t see him making the last_val be at the index as the removed value. Meaning he just popped the removed element off but kept it earlier in the list and lost that edge value.
    Please correct me if I’m wrong 😅

  • @madebyut
    @madebyut 2 роки тому +16

    Hiring a cocky person is quite dangerous no matter how smart they are.

  • @louishauger3057
    @louishauger3057 11 місяців тому

    U can just return a random number in range of the index and return the value at that index

  • @alonewithgodd
    @alonewithgodd 2 роки тому +1

    I am happy to know I almost guessed all the approach correctly!!

  • @kst-owo
    @kst-owo 3 місяці тому +2

    disqualified for cheating 😂love how calm NeetCode is

  • @mpi3602
    @mpi3602 2 роки тому +3

    I think the end solution doesn't consider removing a value from a map that has only one index

  • @charminghostes
    @charminghostes Рік тому

    hey hey dude, thanks for the vidos!! now a cool mood for the whole day :)))

  • @heatchecknyc2142
    @heatchecknyc2142 2 роки тому

    Enjoyed this video so much i watched on both your channels. Can you make a series of this?

  • @mr.rodzhers8663
    @mr.rodzhers8663 Рік тому

    Well shown who is a front-end developer, thanks

  • @house0795
    @house0795 2 роки тому +1

    Awesome, more of that would be highly appreciated

  • @c_hlee
    @c_hlee Рік тому +1

    I've 100% coded in Google Docs for Google interviews before. It was painful. I turned off the auto-correct settings right away

  • @pabloh.7536
    @pabloh.7536 2 роки тому +1

    This is so clutch. I have a Google interview in 2hrs

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

    Idk if he knew this, but he could just store the numbers in a dictionary by converting it into a str using the random choice on it. If it does the random choice in the dictionary, it would take only the keys as the list and get a random str number

  • @Y2B123
    @Y2B123 2 роки тому +8

    Should we delete empty value-indices pairs from the map as we are removing? It seems to me that leaving empty sets around not only waste space but also breaks the if statement above.

    • @MRTNWSS
      @MRTNWSS 2 роки тому

      I agree.

    • @marspark6351
      @marspark6351 2 роки тому +1

      Yes. That's something they missed

  • @protodimbo
    @protodimbo 2 роки тому +3

    42:27 i'm dead 🤣 Neetcode, thanks for the video, i want to be smart like you