C++ Interview with an Amazon engineer

Watch someone solve the what are my friends buying problem in an interview with an Amazon engineer and see the feedback their interviewer left them. Explore this problem and others in our library of interview replays.

Interview Summary

Problem type

What are my friends buying

Interview question

1) An online retailer is releasing a new feature called "What are my friends buying?". The feature lists a set of products that you have not already purchased from the things that your friends have bought, in order of most bought to least bought. To help with this, we have the following 2 APIs. Complete the function that takes in a person and returns the items that the person's friends are buying. 2) Instead of your friends, what about your social circle? A social circle of a person is defined as the person's friends and their friends.

Interview Feedback

Feedback about Manxome Possum (the interviewee)

Advance this person to the next round?
Thumbs up
How were their technical skills?
3/4
How was their problem solving ability?
3/4
What about their communication ability?
4/4
### Context Conducting a mock virtual onsite interview for a mid-level software engineer. Evaluating the candidate on technical questions only. I posed one technical question, targeted at evaluating coding with a focus on data structures and algorithms. ### Summary You met the requirements for a mid-level software engineer. You have a solid problem solving approach and appropriately used data structures and algorithms to solve the problem. You did not reach any extensions to the problem. ### Technical Evaluation You have a solid problem solving approach, clarified requirements well, proactively used examples to clarified requirements. You needed a minor hint to focus on solving the right problem. You solved the right problem. Specifically you used appropriate data structures and algorithms and could state the time and space complexity of your solution. Suggestions for improvement: - Try to start the question faster. You don't need to re-write the problem statement out, just a verbal confirmation is sufficient. This would have saved 4-5 minutes and in this case would have let you start one of the extension questions. - Inserting into a heap-based priority queue is O(log n) per insert, hence if you construct a priority queue based on inserts it will be O(n log n). One way of remembering this is that nothing can ever come for free - if you insert n times into a data structure that promises to allow you to always get the min/max element in O(1) time, there must be some kind of rebalancing going on internally. See: https://stackoverflow.com/questions/2974470/efficiency-of-the-stl-priority-queue. However, if you construct a priority queue based on a sorted array there is a special optimization that allows you to construct it in O(n) time if you have all of the values available ahead of time by using Floyd's Algorithm, see: https://en.cppreference.com/w/cpp/container/priority_queue/priority_queue. - When refactoring code to address extensions try to stick to using helper methods, as you were doing. For a mid-level SDE or higher interviewers are looking at what your instincts are as requirements or problem statements change or become more complicated. Does the candidate just hack the code in-place or do they start generalizing to handle the new requirements and minimizing the code changes needed?

Feedback about Orange Malamute (the interviewer)

Would you want to work with this person?
Thumbs up
How excited would you be to work with them?
4/4
How good were the questions?
4/4
How helpful was your interviewer in guiding you to the solution(s)?
4/4
Excellent interviewing skills and asked multiple follow up questions. Guided the interview in right direction.

Interview Transcript

Orange Malamute: Hello, can you hear me?
Manxome Possum: Yes, how about me?
Orange Malamute: I can hear you clearly. How are you doing?
Manxome Possum: I'm doing good. Thank you. How are you doing?
Orange Malamute: Great. Thank you. So before we get started, I wanted to ask you a few questions just to make sure I give a kind of interview. Is this the first time that you're using interviewing.io?
Manxome Possum: Oh, no, I have been using it. This month, last month.
Orange Malamute: Okay, and what position are you interviewing for?
Manxome Possum: So I am interviewing for the software engineering positions. So I have an interview coming up at Facebook next week.
Orange Malamute: And what level are you interviewing for?
Manxome Possum: I'd be interviewing e4 level.
Orange Malamute: Is that a entry level software engineer or is like a mid level?
Manxome Possum: Mid level, is like next to the entry level position. Which is SD to position kinda.
Orange Malamute: Okay. And how prepared do you think you are?
Manxome Possum: I think I'm prepared. I've been preparing for the last month.
Orange Malamute: Okay. Fair enough. And so you're interviewing with Facebook next week? Are you also interviewing with any other companies? Or are you interested in other companies?
Manxome Possum: Yeah, I mean, I'm applying to other companies. But that is the only thing that is, like in process right now.
Orange Malamute: Okay, so what I would like to do today, that is, the kind of interview we'll do is is typical, maybe not for Facebook, but for other companies. Maybe Facebook is, each onsite interview that you have will probably be one hour long. And it'll be a mixture of behavioral and technical questions. And so that the company that I work for, we give two behavioral questions, and each one last 10 minutes. Let me give one technical question, last about 35 minutes, and then we leave time at the end for you to ask questions. So, for you today, I'm going to give you one technical question, and then we can I'll make a note of when 35 minutes is finished, but we'll just keep going afterwards and just keep doing the question.
Manxome Possum: Okay.
Orange Malamute: Okay, can you hear me typing in the background, I'm just typing notes. I apologize for the noise. Cool. So what I'm going to do is also at the company that I work for, and probably at Facebook interviews too, the interviewing.io environment lets you run code. But when you do interview with these companies, you will probably not have the ability to run code. And on top of that, when you're doing the interview, the interviewer is looking for you to try and demonstrate that your code is correct. You're walking through it manually. Yeah. So you can feel free to use C++ that's fine. But what I'm going to do very quickly is turn it back to plain text and put the description of the problem and I'll put it back to C++ that way the problem description will be commented out you'll see what I mean. Okay, put it here. I'll put it back to C++ for you. And so it didn't quite work that oh it's because I used C type commenting... let's just changing the way I format my comments to be more compatible with C++. Here we go. And so just please read through the problem and let me know if you have any questions.
Manxome Possum: Online retailer is releasing a new feature called What are my friends buying. The feature list a set of products that you have not already purchased from the things that your friends have bought. To help with this we have the following three theories complete the function that it takes in person and return the item that the person is painted by. Okay, so we have a new feature called what are my friends buying and this... Okay, let me write out my thought process here. Okay. That is what your friends think. Because we want to get list of products someone thinks they're buying. So, the feature list is set up or that you have not already purchased. Recommended products are not bought by person that is asking for the list. This will be the product that his friends are buying but it is not in that something that person has bought and the things that you're friends about and in order of most worth to least worth. To return list should be sorted by frequency from high to low. Okay, to help with this, we have the following two APIs completed. So, we have two APIs where we get purchases okay. So, we give you a person class and then it will return the purchase. Okay, yeah, that we definitely need. The API can give any person we want list of products that that person purchased and the second API is even a person we want to know the friends list of the person. On product list and return the friend list. So, now I have the question sorted out here is compute the function that takes in a person okay. So, there is a person class and returns the items that the person's friends are buying okay. Which is sorted in high to low frequency that means, I have to write a function, which will list a number of items, maybe some string of items, so, I'm just assuming that the items product items will be some string in the form of a string the name of the item.
Orange Malamute: So no, so like the API is returning actual classes with a with an A or with a type capital item and then this capital P person.
Manxome Possum: Okay. Okay. So, this will return a vector of items and this is completed so, you can say items or personal thing okay. This may be recommended and here we need the input for the person when will you want this list. This should be the function signature look like. Okay, so, before I start, I just want to clarify. So, how many number of items I need to return the recommended products?
Orange Malamute: All of them that meet the problem description okay.
Manxome Possum: So, there is no fixed number. So I should return everything from the friend list whatever is not there in the person's purchased list. Okay. All items that are purchased by a friend. Okay. Let me start with one example. Maybe here. Person A, has three friends, B, C, and D. And products bought by each person. Okay suppose I have two friends and these are the products they have brought then once a call the function it should return for Person A should return that 0 is on. So, these are the things that have already been this let me see I've already purchased. So, five and 6245 and six and seven eight and nine. So, this should be the answer but we want it to be sorted by frequency from high to low and the frequency will depend on like how many persons have actually purchased that particular product okay. Data structures, first I need to have a data structure to store... okay so, the API have it will return the list of products in the form of a list. Okay that you want to check whether all those products are bought by other persons or not. So, we actually use a dictionary here to store items and for each person I am getting a list of friends okay and for each friend I can query all the products they have purchased okay that means I need to I need to get for each person I will get this list at the end and see each person in that list I have to query their products but I have to sort it by frequency that means for each product I have to know that how many persons have got that product okay. So, I need a another data structure where I should store the person's record each of the products how many persons have bought that product Okay, let's say that this is a dictionary item to person, this will be account for person. So this way I will know that okay the product 0 has been bought two things for years been bought by two people and this episode this will help me in to bring the frequency right. So once I have this then I should sort it based on the frequency.
Orange Malamute: Just to be clear on lines 26 to 28 that you can purchase at API can return multiple items for purchase if a person has purchased at multiple times.
Manxome Possum: Okay, yeah, yeah, sorry, I missed this. It says multiple items an item will be in the list multiple lists that means if it is like six again. This is like anything this won't be counted. So the focus of the question of most of our tools so this most bot is only the criteria is that the number of different persons is not the same person.
Orange Malamute: No, it's purely purely the number of times it's purchased regardless of who's doing the purchasing.
Manxome Possum: Okay does not matter like with the same person is buying that product multiple times? Yes, okay. So, it is simply the count of instead of to store the count of purchases an item meeting. So, first I query the person list and for each of the friend list, I get all the products and for all those products, I store it, I map it to the product like I dumped to the counter purchases. So, this way, I have to do is this two things product versus two things product three density three is what is two things like this. So, this dictionary should look like this being a count. So, once I have built this count, that means I have to go through each of the the current person and all its friends and create this mapping. So, once I have this mapping and I stored in the first dictionary, I just store the items that the current person has purchased. So, this will be a unique list of items that current person has purchased something I can go through this I can go through the entire list of items in this one the second dictionary that I have counted like mapping of each item to count and if any of these items are present in the first dictionary that means for the current person I should word that it should just skip that one and keep on returning the other ones okay. So, this part now, I am clear that how I can return the items to now I think I go back to the question how do I sorted from high to low frequency. For sorting it from high to low frequency instead of okay once I build this dictionary, I can put it all these items as a pair we in a priority queue or like a heap data structure that way I will put the highest yeah, but the third will be to use a priority queue with a store with count and item ID. So, this with and I store it from axiom monitor, high count to low count. So, all these items based on their count will be sorted will be so this will keep you from high to low purchase frequency. So, once I have this, then I have to keep popping each of the items at the top of the priority queue and if that item is in the first dictionary for the current person that has purchased items, then I should skip that and all others will just return. Yeah. So this way I will... So the returned items will be sorted from high frequency to low frequency and I will skip the item for the current person they use. Like the person that is passed to the function that I will skip. Okay, so now have the thought process like how to solve this. Maybe before I said that, I want to go through the time and space complexity of the problem. The solution so first I'll be using a dictionary to store the items, that means, it's the current person or you will be going through all the friends and I will be going through all the items they have purchased. If you talk to friends, and indeed the number of items purchased by the person and including, so, I will be going through this whole list and and i will store it in the priority queue for each item. Okay, so maybe, let's see, you will be the unique number of items purchased, they are in the for all the users. And for those many items, I have, I am using a priority queue that will be initially distributed n plus m just to store get all these values for the dictionary, like populate all these data structure. And then once they have the unique number of items, so those many items to build this it will take u time. But once they start popping each of the items, so it will be O(u log u). So this is the time I will take this will be the entire time. Yeah, this will be the time for the whole algorithm and for space... And here, I am assuming that like I'm not accounting for the call to the API, because that I kind of hold on to minutes how much time it takes to get the purchase list. Can you hear me?
Orange Malamute: I'm sorry? Could you repeat the question?
Manxome Possum: As I was saying that here, I'm not accounting that this goes to the API and get purchase API is the constant thing for me.
Orange Malamute: Oh, yeah, that's that's fine. You can assume that. Yeah.
Manxome Possum: And space complexity will be storing the items for the current person and then storing the items for the for all the unique items and storing the count those one I'm also storing the count in the priority queue. So, this will be u plus u and on the output will be here that will also be order of U. So, this will be order u. And this is essentially... Yeah, this would be the final time and space complexity.
Orange Malamute: Okay.
Manxome Possum: Okay. So, if you find it okay, can I start coding now?
Orange Malamute: Yes please.
Manxome Possum: Before I start, I have one question is this item and person and these are some classes, so, how do I store it in a successful can they lead to some kind of any query some kind of ID or something for this item class and person class.
Orange Malamute: You can either query an ID or you can assume that it is it can be inserted into a dictionary as a key.
Manxome Possum: Okay, the next function signature is here. My first tip is to get the items and store them in the dictionary here. Test list is already processed by the person test by the person... so, that is good was to see when this current person. All items that the current person purchase or you just put it into this dictionary to store only the unique items. Step one... then step two is to get all the friend list and for each and query each of their items. So, before this I should also create a dictionary which stores the mapping of item to count of the number of purchases. So, this will be item to integer for the number of count so, this is I item to count mapping, and for the current person also I should add are the items count. So, items to count different item is plus one now, I need to get the friend list and for each of the friends I need to get all the items they have purchased. To the friend in the person's friend list, this is the API the friends and for each of the friends I need to get on the items they have purchased. I get all the jobs here and they update the count here. So, I'm trying to count particular items is plus one. So, now I have the step two done. Now the step three will be to create a priority queue... Where I store a pair as first is count and second will be the item. This is a max priority queue, as it is a pair I do not have to write the custom function because it will by default it will use the first element of the pair to compare okay. And here I have to go through all the elements in the item to count list. You the second that is second is to count for the item either first items ID. Okay now I have to return a result. So, the result will be in the form of the vector and in this I need to return all the elements that are there in the priority queue which are not in the third person's purchase list. So, I will go through the for loop until the queue is empty for the entire item second, that is the item ID. So, if this item is purchased that was count if it exists in the dictionary then skip this if it is not exist in the dictionary... okay if it is not purchased by the current person then we proceed into the result. Otherwise and we sort by key. Yes, I had the code complete code and think let's go to this example. Great, okay. I just copied this example here. So, that it is easy to follow. Maybe just change some values here to this one okay. So, we just declared this dictionary here then we declared another dictionary to store the purchased items. So, first we, okay. So, we are queerying for the person A. That means this concern is calling person A here. And for the person A we will first query the purchase that the person made the purchase, it will return 0123 maybe I will make it one more here is making zero. So, it will create an all these numbers here. And for each of these items, that is 01230 it will increase the count for each of the items that means at end of this step dictionary will look like zero has count of two one has count of one towards one and 3 has count of one. And as this dictionary is storing only the unique items, so, this will have item 012 and three in any arbitrary order. Sure. And in the step two, I call the friends a person so friends a person a it will return B and C for either the items the person that is the solution first do it for B. For B, it will return to the 34566 that means the dictionary will become this list the previous state and I will add the count for three to two. Count portfolio will become one count for five will be one and count for six will be two. This is for B and next then is C, and for C, will return purchases that are 73407. And here we already have three so three is known because three, four become two, zeros count becomes three and sevens count is two. There are two 7s here. This is a dictionary. Now we want to push all these items into the priority queue. So priority equals 01234567. And here the highest count is 0 and 3, it will be three comma zero, then C comma 3, then four six and two. So this is the priority queue. And here we come to the result in the result, but go through each of the items or things first, it will be three. And so initially, in this list, we have 0123. In this property, this here, this is the purchase list of the first item in the priority queue will be item zero, which has frequency of 3 and two is already there. So it won't be pushed into the result, then is item three, the three is also there, so it won't be pushed into the result, then item two It is also there. Then, 0 is 3, and then it is four sorry, this is item four. That means the result will first give 4 here. And then item six, item seven, who is already there, one is already there. So this will finally return four six and seven.
Orange Malamute: Cool. All right. I agree. I had a few clarifying questions. Thank you for walking through the code. But going back up to line 74 when you determine the time complexity. So let's only focus on the u for a second, unique number of items using a priority queue. What again, was u plus u log u?
Manxome Possum: Initially u is to build a priority building.
Orange Malamute: So it is O(u) time to build a priority queue?
Manxome Possum: To build a heap of an items takes orders n?
Orange Malamute: No, I believe it takes n log n to build a priority queue unless the input is sorted. Each push requires a rebalance of the heap which is log n.
Manxome Possum: Yeah, each function takes login. But initially with this, you will be setting 1 2 3. And finally, going till and this initially the log value is not actually a log, the latest with this something much lower than log n because the number of items are lists. I exactly don't know how the priority queue works. But if it is a heap, then it will be directly like only your order of n to do is guaranteed to take hold this one works.
Orange Malamute: That's fine. I do I believe that it's n log n to construct unless you have an ordered input. So I'll leave it I'll leave a link in the in your comments. And you can take a look at it later. So let's move on from that. So now we're at we're at the end of the times this is 35 minutes. So what I want you to do is just give you some feedback initially, and then we can keep on going with problem. Okay, so yeah, this was you, you gave a very good response. And you were very careful in clarifying the requirements. And you gave good time and space complexity descriptions. You wrote code that looks. I agree that it works, we step through it with an example. So you gave a good response. I think my only feedback for you is that initially when you were I think it's on lines 34 to 40. I think you were when you're when you're clarifying the problem. You don't need to type it out again. So I think I think what, where you started on line 42 with the function. The method signature is great, but just typing The problem again, I think use took you four or five minutes. And I think you could have saved yourself four or five minutes. The reason why I say that is because interviewers typically like me, we always reserve some extension questions for the candidate. And once you have code, then it's much easier to reach the extension question without, with actual code as well. So ultimately, you're only evaluated on the code that you write down. But we, I also evaluate you on your problem solving abilities. But I think you don't need to write it out again, lines 34 to 40. Do you find that helpful to you when you do that?
Manxome Possum: I just wanted clarity like what exactly I'm going to do. But yeah, that took five to six minutes, I think.
Orange Malamute: I think you, but you're, the pure codification of the problem was excellent. I just think that you could do that verbally. And just start in line 43 that always give the method signature, but you can just start, you can first clarify verbally, engage me in the conversation, and then just go ahead and clarify with the method signature.
Manxome Possum: Okay, yeah, keep that in mind.
Orange Malamute: Cool. And also with the priority queue stuff. You know, I wouldn't worry about it too much. But something I wanted to ask you is, is there an alternative to using a priority queue in this for steps three and four.
Manxome Possum: Instead of priority queue, I can use a little set that is like the last BST in C++. So that is a map. I'll be I will have to be on the other side. So keen, I told me a map it will be set with the same as we said.
Orange Malamute: Oh, an ordered set with the same pairs.
Manxome Possum: Yeah, but this will be as high as the time complexity? Well, you should be the same as inserting and deleting and also same log n.
Orange Malamute: I agree. I can see how that would work. And also something else to consider is, what if you could use sorting to solve steps three and four?
Manxome Possum: Yes, I can do sorting. Yes, if this step, actually, if this step is log n, they can log n at three to build a priority queue, then we can really get away with sorting so that it is in log n. And then I know the order of the items directly, stored in a like a list.
Orange Malamute: Given a priority queue, let's suppose it was o n to construct. We both agree that in order to retrieve the items as n log n to retrieve. So in the end, all these all these solutions are equivalent.
Manxome Possum: Yes, yes. Yes, that's correct. Even if we don't use it. Yeah. So the list and sorting also give the ultimate time complexity will be same.
Orange Malamute: Cool. These are all questions that I would like to ask you during the interview. So during the interview, I would probably interrupt you while you're while you're doing your example. So I could ask these questions, because this is part of my evaluation criteria. Okay, so here's just a very basic question is like, why did you choose unordered map and unordered set as data structures.
Manxome Possum: These will have average constant thing existing. So in C++, they have, I think, some kind of hash function to implement all this on a road map and set. But in if I use the regular map and said that is essentially a self balancing, binary search tree, which each of the operations are guaranteed to be logarithmic timing.
Orange Malamute: Okay, great. So what I'd like to do is give you the extension to the question I would give to a candidate. So and then we'll just keep going until hours over. Sound good? Yeah. Cool. Let's just do it. So just to be clear, you you met the bar for this question, but in future, try to maybe exclude the typing out of the description so you can reach an extension. On to put this on to line 33. If you want to copy paste your code or whatever, that's okay, but I'm going to put it on line 33.
Manxome Possum: Instead of your friends whatever to this yellow circle. This is your circle of a person is defined as the person's Friends and dear friends okay that means friends, it has been c and d the heads and maybe D then we want to get all the list of items that all the principles have purchase. So, before I think through us all I think the first question that comes to my mind is So, if a different of these like mutual friends simply be those who end up a or it is only a one direction?
Orange Malamute: Good question. At the end of the day, so, it may or may not be true sometimes sometimes B could be fun today, sometimes B might not be friends with A.
Manxome Possum: Because if it is a mutual friendship, then the problem essentially comes down to finding the connected components in a undirected graph with all this a be the node and this is the friendliest will be the edges which are connecting from A to B, A to C and A to D. Similarly, for each of the person, if I take it as a node in a graph, and all the friendliest will be each of the edges. And if it's a mutual friendship, then I'll extensively I have to find the connected component in a undirected graph. And to find that I can use either breadth first search or depth first search. Let me start with any one of the person.
Orange Malamute: So I agree that in general, if you want to find directed components, you can give an algorithm but remember, you know, our problem statement is we start with a person. We know we're starting with ourselves. I agree in the general context, but very specifically, this is like a retail website. We it's just ourselves, we know we're always starting with A.
Manxome Possum: Okay. Yes, if we are starting with a that means we have to keep on exploring all the friends, then it is simpler in the sense that we just have to keep a like a unique list. So that is essentially a dictionary where we keep one for each of the friends we call what they need to say I will be like kind of form a loop. So it will be it should be some kind of data structure where we know that what all friends we have already visited. Okay. Yeah, so, this I think the same list, we can use the same dictionary and here we keep on putting other things we start with a here, and if it has been BCD that means the dictionary now has A, B, C, and D. And next we explore for B and B has e f and D E F these already D is not already explored these has to be full of terminals. This will be so this will be essentially depth first search starting from a and whenever I find friends for each of the friends, then I'll keep putting in a unique list. So that is my goal is to starting from a I want to explore everything that is connected to it. Yeah, that's a thing, the goal here. Okay, so if I hack on, I failed to convert it into a code. Let's see yes. Just putting this comment in the bottom. Okay. I want to explore each of these things here. Instead of just winning through the Friends of the current person I have I should be exploring everything that means I suppose I have another function to do that. We have a data structure list of persons the person, person is already... Okay, if that person is already explored, then we don't need it. Yes, so this will the three lessons early populate all the friends, like all the friends in the circle of that person in this particular dictionary. And once this part is populated, and that means if I do here... So, instead of doing this, I should be doing the step two I should be...
Orange Malamute: Before you're used to just just speaking about the method you created. So, the problem statement was a social circle of a person is defined as a person's friends and their friends. So, is this your method meet that problem statement?
Manxome Possum: So, this will actually have to clarify that this is something that is if I'm using a class so this is in the class, or I have that's fine. Yeah. Yeah, all I have to like pass reference to this. This is constantly What if...
Orange Malamute: I suppose, suppose in your example, A is friends with BCD and B is friends with EFT and let me I'm going to type in line 155. Suppose, f is friends with I won't go too far. So that the problem statement is I only want to see the Friends of BCD I don't want to see g h i or z that makes sense.
Manxome Possum: So, it is only that is one level down is not going to be all the friends of friends of friends and friends. Okay, I think I misunderstood the question then. I can a thought that this is a sensor. So this is like kind of pre risky.
Orange Malamute: If you keep going with all the imagine on Facebook, if you just kept going with all the friends and all the friends, you would probably pull the whole graph.
Manxome Possum: That'd be pretty can be some billion people. Yeah, it could be one layer.
Orange Malamute: How would you modify to handle one layer?
Manxome Possum: Then we'll be just so instead of doing going through this, and I recursively calling that function, so I have to refer each of the friends then I have to call the friends that name was here. We have to call for each other friend explained to you could do that.
Orange Malamute: But what if then I extended the problem and said I don't want just friends or friends. I want n levels.
Manxome Possum: Okay, yeah, that's true. That means I need to explore only till certain level. So, then it will be a good idea to use breadth first search where they limit my distance to n. I have to find up to n level of friends and I explored only level instead of this function, I should be using a breadth first search where I start with a and a has nodes d c and d. So, this will be a level order traversal that means, that each level, all the friends so, that is like one level and then keep on in increasing how many levels I want to be. So, the initial problem statements it will be distance will be two that is all friends and then those ends next level friends. So, they just write the core algorithm in it. So, if I start with I have a queue and you initially has to initially the person a and I say until queue is empty and here I define the levels of level something n and then I do queue size minus one to zero minus all the friends that are there in the current level and explore all their friends sincerely. So, queue is not empty is greater than zero and for each level introduced into n minus one. Friends of the current person that will be the queues of item here each friend in get friends of that person I keep on adding those to the queue. Yeah. So, they say just stop at how many levels I have defined. And it sincerely actually one thing I missed here is whenever I am popping the items, that person has to go into the dictionary will have like a list of unique friends. So, this will essentially go to the third person if at the end of iterations, I will have all the friends of the person starting with that I can then use that means at line... Okay, so this I do not need this at line 119 when I was calling the get friend for the particular person, I should be iterating over all the persons that are there in the circle. And that is in the dictionary which has all the friends.
Orange Malamute: Perfect. Yeah, you don't need to write the code. I understand what you did with the BFS and you could put it inside a good friend circle and you can use it there. So, yeah, just because we have one minute left. Yeah, what I would say is for this question, when an interviewer poses an extension to the problem, you solved it correctly. But be careful that you likely try to find you correctly made a helper method and line 143. But then when I clarify the question said, oh, it's only one level that you started. You started ignoring your helper function and you just started editing the code on line 190. I think your use of the helper function was excellent, but like because the way the way the interview would go is you make a helper function only handles one level and then I would say, oh, what about me? When you say, Oh, you want to have n, you just, all you have to do is change the helper method. You don't have to change your core logic and recommended products.
Manxome Possum: Yeah, I think this, this function was not suitable for that particular project. I wanted to change to BFS. Now, the initial layer study BFS.
Orange Malamute: You could do, yeah, but it's something else. If you really wanted to use recursion, which is fine, you can easily you can easily have the recursive call accept an integer parameter and you just decrement that when you do the recursive call, and then you can just stop when you hit zero. Yep. So like, I'm using helper methods, it was great. That's a great instinct. That's something that people look for for mid level SDEs. So try not like once you have working code, you know, the recommended code is already already so complicated. You don't want to like keep adding more to it. You want to try and refactor it out into separate methods.
Manxome Possum: Yes, yes. Yeah, that makes sense.
Orange Malamute: Cool. So this is an hour. So we're out of time. But do you have any questions for me?
Manxome Possum: I just couldn't like how was the communication from my side, were able to understand everything or was I not clear at some parts.
Orange Malamute: Your communication was very clear. You use the text editor in a very good way, especially when you're going through examples, your technique is excellent. So you don't need to like you don't go into too much detail that you have enough detail. So like, for example, line 121, when you're telling me what's inside the item count, dictionary, or map I understand. So your communications good. Different interviewers have different requirements. But you don't need to start with time and space complexities, you can add, you can end with it if you want to. So you don't need to get bogged down too much. Because sometimes what will happen is, this happens a lot as you as you write an answer to the question, you realize, Oh, I got something wrong. Oh, I forgot to do this, and you when you do this. And so that's why if you first write the code, then you do time space complexity, there's less risk that you have to go back and fix up. And also, I think I have more chance to finish the code. Yeah, you know, for better or worse, you know, I misspoke. The code is not the only thing that you're evaluated on for this question, actually, I'm evaluating you on your use of data structures and algorithms. And you did very well. But I need code. It's the code is not optional. But the written everything else is optional. But eventually, but for this question, time, and space complexity is not optional. I just think, on average, if you do it after the code, they'll be nice need to go but less need to go back and fix it up.
Manxome Possum: Yeah, yeah.
Orange Malamute: Yeah, otherwise, yeah, this is all all. Great. Do you have any other questions for me?Good. I'll give you I'll give you one other extension to the problem, which is not difficult. But if you want to do it, try it out. I'll post this on line 47. Not difficult, but about, you know, the code is not difficult. But maybe more interesting is how does this change the time complexity is perhaps more interesting. Yeah, just just try it out. Try to afterwards but yeah, that's all that's all for this interview. So thank you for your time.
Manxome Possum: Thank you, thank you for them.
Orange Malamute: If you want to copy paste this stuff, feel free to copy paste it now.
Manxome Possum: Will this go away? I think it should be there in the it'll be there in a video recording.
Orange Malamute: Yeah, I have a copy, and it's good.
Manxome Possum: Alright. Thanks a lot.
Orange Malamute: Yes, thank you.

We know exactly what to do and say to get the company, title, and salary you want.

Interview prep and job hunting are chaos and pain. We can help. Really.