🚀 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: kzitem.info/news/bejne/y2qB3Zx4s5uAo5w
@alisonoz7219
Жыл бұрын
Yeah I'd like to see that 🤩
@zesanurrahman6778
Жыл бұрын
I became homeless. I am depressed
@slayerzerg
Жыл бұрын
yeees
@smtp_yurzx
Жыл бұрын
It seems only fair and right with the world. I mean if you prefer balance in the universe rather than chaos.
@ralph_d_youtuber8298
Жыл бұрын
Hi, sorry isn't duplicate problems easily solved with sets, as this doesn't allow duplicates, and it's call is already random.
@Dulandor
6 ай бұрын
"If there is a problem, just throw a hashmap at it." - someone really smart
@subhrajyotisen7218
6 ай бұрын
Funny how true this is
@Naveen-b5j
5 ай бұрын
@@subhrajyotisen7218 why not Hashset here ? until follow up question
@subhrajyotisen7218
5 ай бұрын
@@Naveen-b5jthe 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
5 ай бұрын
@@Naveen-b5j you need to store the index as the value.
@harshwagh243
3 ай бұрын
Works all the time
@nikhil_a01
Жыл бұрын
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
Жыл бұрын
😂
@user-lt6hz7jh2p
Жыл бұрын
I 😂😂😂
@NotNazuh
10 ай бұрын
😂😂😂😂😂😂😂😂😂
@tahashakeel
6 ай бұрын
I didn't notice that, can anyone paste the timestamp. I watched the video twice still didn't see it
@AbhishekKumar-cl6ou
6 ай бұрын
39:19@@tahashakeel
@Protocoding
Жыл бұрын
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
11 ай бұрын
I just hate to ask questions for the sake of asking questions though...
@eesnehhil
10 ай бұрын
@@MichaelButlerC frfrfr
@AnimeZone247
4 ай бұрын
@@MichaelButlerCyou’re going to have to do that during the actual job
@BTC500k
Жыл бұрын
“In your real interviews, do you talk the same way..?” LMAO that is the question I wanted to ask lol
@pinecedar180
11 ай бұрын
It was obviously a frank discussion between friends
@parvscripter
5 ай бұрын
@@pinecedar180 but you can be pretty frank just don't be unprofessional
@decomush
5 ай бұрын
I'm 5 min into the video and I wanted to ask that
@WoWUndad
3 ай бұрын
@decomush do you think you're superior for being socially inept and not realizing these are 2 friends ?
@decomush
3 ай бұрын
@@WoWUndad not really, just a fair question to help out the guy
@willboler830
Жыл бұрын
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
6 ай бұрын
True, IMHO I think he should ask all the possible questions. To ease the doubt.
@SankarshanGhosh
Жыл бұрын
This is the first time I watched a 40 minute video. Real fun, we want more of these!
@krovvidisupraja6822
Жыл бұрын
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 😃
@davidtran9455
7 ай бұрын
well did you get the job?
@adityasankhla1433
4 ай бұрын
@@davidtran9455 😭
@Neilblaze
Жыл бұрын
Been watching Mock interview sessions for a long time, but this is by far the most enjoyable session for my all time :)
@dacattilearnsenglish3141
8 ай бұрын
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.
@rajingale5776
Жыл бұрын
The collab we waiting for..🔥 The only 2 coding channels i subscribed and getting that collab is awesome..
@atharvagupta9355
Жыл бұрын
This interview made me realize that I can do it too. Thanks, Neetcode
@marspark6351
Жыл бұрын
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
Жыл бұрын
excellent observation
@ProfessorQuality
11 ай бұрын
what if you want to remove the number first in the list, you can't use pop() instead?
@xingzheli7431
11 ай бұрын
It's remove by value, so it's worst-case linear time for an array.
@Biggyweezer69
8 ай бұрын
@@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
8 ай бұрын
@@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)
@yitongxie6574
Жыл бұрын
the last part you ask 'do you talk like this in real interview?' and then 'nothing' really make me laugh
@tedwoldeselassie5715
11 ай бұрын
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.
@jasonswift7468
Жыл бұрын
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.
@SanjanaSingh-mc6re
Жыл бұрын
Can we get more interviews like this one? It was really helpful. Thanks!! 🙂
@heretic7135
Жыл бұрын
??
@utsabkhakurel9742
11 ай бұрын
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
5 ай бұрын
There is no indexing in sets so self.map[value][-1] wouldt work and then he also pasted some wrong java code in
@supastazz
Жыл бұрын
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
@applepine3172
4 ай бұрын
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.
@MrPkmonster
Жыл бұрын
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.
@gnes04
6 ай бұрын
Ngl I thought he'd do a lot better for a meta intern. The first question was easy as balls
@yessirski7868
26 күн бұрын
all about connections. I am sure he still a good programmer.
@chengyuanchang4000
Жыл бұрын
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.
@harryshi1
Жыл бұрын
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.
@ahmedanwer6899
11 ай бұрын
Are ya still down? :)
@madebytiwari
Жыл бұрын
Hiring a cocky person is quite dangerous no matter how smart they are.
@chair_smesh
Жыл бұрын
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
Жыл бұрын
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
Жыл бұрын
yea its kind of a modified version of google docs (at least that's what it looked like) with syntax highlighting
@jose6378
Жыл бұрын
Unironically got a very similar question for Amazon SDE position
@nacereddinebenmerah3538
14 күн бұрын
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.
@karanbhatia2834
Жыл бұрын
This was like actually really awesome. I felt like I was solving the problem with him!
@negarvahid
Жыл бұрын
Bro why didn't you upload this sooner I had my interview yesterday :,)
@ChoiVibess
10 күн бұрын
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
@user-fp4dr1ne7z
Жыл бұрын
But for real, if you act like him in an interview, how would the interviewer view that? Is he being cocky? Or is that confidence? I understand he’s being semi sarcastic because that’s his KZitem persona. But I know there are people who actually act like this in interviews and I wonder how it’s received by the interviewer.
@FryingPan
Жыл бұрын
Assert your dominance. Instantly hired.
@Mechaneer
Жыл бұрын
"I bet you didn't know that!" 🤦🏼♂️
@RocketPropelledWombat
Жыл бұрын
@@FryingPan Should I raise the stakes by urinating on the interviewer's leg?
@NeetCode
Жыл бұрын
He ended up writing some pretty neat code so we can let it slide 😉
@von...
Жыл бұрын
@@NeetCode yooooooo!! he said the thing!!
@SankHar4
Жыл бұрын
Neet code Please do conduct whenever possible it helps the everyone a lot of Learning. Thank you so much...
@janni7439
Жыл бұрын
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.
@christianmorera4127
Жыл бұрын
I love this, frying pan makes coding interviews fun
@salvadorortiz449
Жыл бұрын
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
Жыл бұрын
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
8 ай бұрын
@@mannyb096 removedInt
@5pellcast3r
Жыл бұрын
The collab I didn't know I needed ..... 🙃
@srinadhp
Жыл бұрын
Invigorating! Great questions all around, even greater thoughts and solutions!
@domchiu
29 күн бұрын
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.
@c_hlee
10 ай бұрын
I've 100% coded in Google Docs for Google interviews before. It was painful. I turned off the auto-correct settings right away
@MikeKm-hd1ve
6 ай бұрын
Priceless video!! Thank you so much!!
@diobrando89
Жыл бұрын
this problem seems way too easy for a an interview even in a small it company
@andreainvernizzi8510
Жыл бұрын
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.
@chrisrey2516
6 ай бұрын
i was able to come up with similar solution. I'm happy lol. I was thinking along with him
@creamymain7867
8 ай бұрын
Love the "Now let me ask you another question" at the beginning haha. Very inciteful video btw
@govindbanura3327
Жыл бұрын
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
Жыл бұрын
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
Жыл бұрын
like we say in chile, "que cagon eres" she should tell him with no fear of hurting him lol
@protodimbo
Жыл бұрын
42:27 i'm dead 🤣 Neetcode, thanks for the video, i want to be smart like you
@denhoward6438
Жыл бұрын
Nice video, I can feel the pressure of the interviewee by his word and face
@pranshu_awasthi
2 ай бұрын
How about we generate a random integer between 0 and current size of set. Whatever we get we can get the associated element in the set by using iterator to first element + that random integer. I mean, technically this is possible in C++, but not sure about other languages. However, what this guy suggested was also quite good solution to be honest.
@rinatlollilop2723
2 ай бұрын
its still will be O(n) solution, btw unordred_map iterator supports only ++ and -- iterator
@cowaiicow8802
Жыл бұрын
I never thought i needed this collab until now...
@zweitekonto9654
Жыл бұрын
You never know what u need until its too late. Thats why ur broke.
@house0795
Жыл бұрын
Awesome, more of that would be highly appreciated
@saurabhgambhire-v4o
11 ай бұрын
Funniest, energetic interview I have ever seen , I want confidence like this😅🤣
@Sayan_Shankhari
Жыл бұрын
this is called using an army tank to kill a mosquito 😴
@TiagoDiass2
11 ай бұрын
amazing content guys, loved it!
@Qader112
8 ай бұрын
I have a question. Why not just use one dictionary to insert delete and get random. Why do we have to use an array as well? for the dictionary, the key will be the element and the value will be the total number which should be no more than 1.
@eakishway
7 ай бұрын
Cannot agree it more. Maintaining two copies of the information (a dictionary and a list) feels unnecessary to me.
@Ermorder1
6 ай бұрын
To get random element, moreover with equal probability
@mr.rodzhers8663
10 ай бұрын
Well shown who is a front-end developer, thanks
@codingtroop
9 ай бұрын
I’ve interviewed at Google before and they required 100% coding in Google Docs. It was painful to put it mildly.
@hasson2349
2 ай бұрын
Need more like that, awesome!
@louishauger3057
7 ай бұрын
U can just return a random number in range of the index and return the value at that index
@raven-a
Ай бұрын
My first thought when he mentioned the duplicates was just adding a counter for each value and summing when adding a duplicate, but then calculating probability... Yeah, wouldn't be so easy to pick a random one lol
@yongfulu8984
Жыл бұрын
I know I know. It’s LC 380
@davidkolesom
Жыл бұрын
Love this Mr. Neet Code!
@USNSWE
11 ай бұрын
I’m about 18 minutes into the interview and my first thought was to just use a Set. A set is unordered and has O(1) time complexity for insertion and removal. Does this data structure not hit all the criteria of what he’s asking for?
@Yougottacryforthis
9 ай бұрын
How do you delete random in o(1) amortized?
@ramesh_hegde
Жыл бұрын
From the speaking tone, seems like Intern is taking interview of Neetcode 😂
@thetrends5670
Жыл бұрын
After Dream, NeetCode and Marshmello are the KZitem biggest mysteries.
@BoutDatFitLife
Жыл бұрын
You tortured him a little by not telling him Google Docs has the option to turn off auto-cap character.
@abhishekgarg8769
8 ай бұрын
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
@huntx...8573
5 ай бұрын
why not use a linkedlist ?
@myrtiy
Жыл бұрын
Neetcode’s code is neat! Thank you Neetcode!
@GinjouArmy
Жыл бұрын
Glad I could follow along with the code on the white Goggle Doc.
@ProfB27
Жыл бұрын
I think we should use doubly LL to store the elements and hash map to store key as number itself and reference of the element as value. Removing adding, checking existence all are O(1), get random will now have list of keys.
@yessirski7868
11 ай бұрын
how would you create that?
@utkarshpandey6244
11 ай бұрын
I also thought of the same solution and was expecting that approach to be discussed
@BIELSIMON
10 ай бұрын
Get random would be O(n) if you assume you don't have keyAtIndex in a hashmap, which is the assumption they are making because if you can all you need is a single hashmap (for example a C++ unordered map using .at(idx))
@guitargeorge7255
10 ай бұрын
thought of that too, but you still have trouble and need to use the realization in the video
@charloteelo
Ай бұрын
i just found this channel and found it interesting. Are we supposed to say whats in our mind during live coding session like this?
@ggs137
Жыл бұрын
Don’t understand a lick of code as I am a networking major (just getting into py) but watched the whole thing very interesting!
@ЦветанГергинов-п2л
6 ай бұрын
Im sceptical for that guy as he confused list with dictionary (Hash) and Java with Python ;d I mean he took JS script and placed it like it would really work with python. Also to remove the duplicates the best way is to use set(). Also to remove the duplicates or remove an integer from the array you can use a .popleft() function and then convert the hash to list and append it to the end result
@nick2629
Жыл бұрын
8:03 This guy 😂 39:05 LMAOO
@adennis200
Жыл бұрын
Haha, i dont think any interviewee would ask questions like that. It is obvious that its done by him on purpose to kinda make it more educational for the viewers
@johniedoeee
Жыл бұрын
There will no be a fair random normal distribution because of duplicates inside a list of values. To solve this I suggest to use binary search over a sorted list list.
@harryzhu
8 ай бұрын
regardless of what it is in the array - it's still a random generator with uniform distribution.
@sajitullahkhan
10 ай бұрын
Bro please make more these kind of coding interview videos
@gokukakarot6323
2 ай бұрын
I would like to try saying Naaaic in interviews. That’s confidence
@pabloh.7536
Жыл бұрын
This is so clutch. I have a Google interview in 2hrs
@Mark-tv1zs
Жыл бұрын
How did it go?
@TesterAnimal1
Жыл бұрын
It’s so whatnow?
@detroitpistonsplayoffs
Жыл бұрын
return map[random() % mapSize]; Thats constant time
@IcyGhost_
10 ай бұрын
Why doesn’t he just use the pop() method of a set, it’s O(1) and gives a random value, you can then just reinsert the value back and return it
@eakishway
7 ай бұрын
It returns an arbitrary value, not a random value. Actually, in recent versions of implementations of Python, it pops the smallest value because sets are sorted.
@AftabAhmed-tq7rt
Жыл бұрын
Bruh i laughed so hard when he quickly changed tabs to get the first element of a set . And said bet you didn't know that huh 😂😂
@darnellarford2439
9 ай бұрын
Who asks candidates to use Word to write code?
@amadywr
2 ай бұрын
11:30 when neetcode asks if get_random function can be more efficient? Wouldn't it be more efficient instead of using random.choice, set.pop is used since set.pop removes a random element at constant time and returns it. That removed element can be stored into a new variable and add it back to the set and get_random function can return the new element. This way get_random function is O(1)
@archigoyal7571
3 ай бұрын
That auto capitalisation was soooo irritating, I faced the same issue 😭😭
@INDNICK
Жыл бұрын
I like how he said using google docs is stupid and it pisses me off in an interview 😂
@B3Band
Жыл бұрын
During the time he was talking to himself, I completed the task in Java. I am a complete beginner.
@saveuyghurmuslims2354
Жыл бұрын
man plz do more and more hard and prefessional plz plz we need this.
@brandonwlee2013
8 ай бұрын
What if for random, you just call random on len(dict) and then use that random integer returned to access the dictionary by key , where key is the index?
@grandpy7924
9 ай бұрын
import random class data_set(list): def append(self, __object): if __object in self: return return super().append(__object) def remove(self, __object): if __object not in self: return return super().remove(__object) def getRandom(self): return random.choice(self)
@eddyelamin9015
Жыл бұрын
Do interviews actually go like that? i started solving in javascript following a long and was happy i did good
@MrD3eath
Жыл бұрын
Wait I immediately recognized this is insert delete random O(1) from watching so many of your videos
@annawilson3824
10 ай бұрын
0:16 ever since I failed my last Citadel interview ...
@Allyourneedsmet
Жыл бұрын
fryingpan and pirateking could be mistaken for brothers, they look quite similar
@JT-mr3db
20 күн бұрын
It’s easy when watching it from your armchair to think it’s easy. When you’re in the hot seat though it’s a different ball game.
@haijunsi6107
Жыл бұрын
deadass i had this question for bloomberg
@CrazyMutex
Жыл бұрын
We can use array to store elements. But we can also keep tracking it's size. And when an element should be removed, we can assign it to the last element, like a[i] = a[n-1] and decrease n like n-=1
@elevenkb-uj9xh
Жыл бұрын
How would this deal with duplicates?
@SaltyBoi420
10 ай бұрын
@@elevenkb-uj9xhlinear search would work but time complexity will be fucked up😂
@pwnweb5734
Жыл бұрын
i have solved like 1500 LC question (including this ofc) not sure, m i ready for google yet :P.. neetcode can u help
@Ayushnachore
7 ай бұрын
thank you for this interview and guidance, now they are forcing me to be the CEO of Alphabet.
Пікірлер: 804