Astronomic Koala: How's it going today?
Intrepid Broccoli: Good. How are you? Are you the Astronomic Koala? Interesting.
Astronomic Koala: Yeah, that is very true. And I see you are Intrepid Broccoli.
Intrepid Broccoli: That's right.
Astronomic Koala: That's pretty funny because I'm eating broccoli like right now.
Intrepid Broccoli: How dare you eat my brethren.
Astronomic Koala: Well, I probably don't taste good. I'm a Koala so we won't have the same problem. All right. Yeah, yeah, you're vegetarian.
Intrepid Broccoli: I'm a vegetarian when it comes to koalas.
Astronomic Koala: Yeah, we probably don't taste good. Probably a little bit tough. So... Cool, man. So before we jump in, you know, just want to kind of quickly touch base on like, where you're at in your interviewing process? And, you know, like, if you're looking for anything, in particular for this one.
Intrepid Broccoli: Yeah, thank you. I'm, I've just been referred by a current Google employee who's a former colleague of mine. And I'm looking at jobs in data science and machine learning engineering. And I have not yet applied for the jobs with the referral. Because I want to, you know, kind of pick my moment, like when I've done plenty of practice and stuff, but I know that there's like a 30 day time limit.
Astronomic Koala: That is very interesting, actually. Because, yeah, I have a background in machine learning. So in particular, though, is this one is dedicated to coding and data structures? Is that what you're expecting? Yes, it is. In fact, I've I've taken one machine learning interview from interviewing.io. That was good. One thing that I noticed that is missing is the data science focus on these interviews. And so that's an area where I feel like I've had less practice than I wish I had in terms of interviewing when I don't know whether it's working with pandas, or whatever it would be. But yeah, so anyway, that's like kind of what I feel like I'm missing the most. But because I just recently got this opportunity at Google, I'm going to do this algorithms and data structures, this interview with a Google, you know, Interviewer. And then similarly, I'm going to do a machine learning engineer specifically at Google.
Intrepid Broccoli: So those two separate, like interview tracks where you can do both at the same time.
Astronomic Koala: Are you talking about interviewing.io or Google?
Intrepid Broccoli: Oh, no, I mean, I Google it from your last comment, it sounded like there was like you're interviewing for two different roles at the same time we're doing.
Astronomic Koala: I wasn't clear. So what I mean to say is that on interviewing.io, so I understand that whether, I ended up getting an interview at the actual Google company from a machine for a machine learning engineer job, or a data scientist job. Probably the preliminary interview will be something more like a LeetCode thing. Um, I think like, probably, you know, this algs and data structures stuff. And believe it or not, I'm actually sometimes I'm weaker on those types of interviews, but I am on the actual, you know, theory of machine learning and stuff. So I need to practice this as well. But what I was saying earlier is that I'm, I'm fine. I'm simultaneously doing practice interviews on interviewing.io from you on algs and data structures at Google. And also, I'm, I purchased a specifically machine learning interview from Google on interviewing.io. Does that make sense?
Intrepid Broccoli: Got it. Got it. Okay. That makes perfect sense. So, yeah. Okay, I got a I got a wicked question for you today. It's from Google on site. So this is totally the difficulty you can expect. I will, you know, give you a copy here and say that this is for the SDE track. I'm not quite sure if they do, like differ significantly in terms of like, difficulties, but I would probably guess that it's the same quality. So this is probably going to be pretty representative for you.
Astronomic Koala: Great. Did you say SD like system design?
Intrepid Broccoli: No, sorry, like, software engineer? Yeah, like the raw track with no machine learning or whatever.
Astronomic Koala: Wicked. We can possibly branch into a second question, but it's definitely not expected. In a real interview. You just be expected to solve this one. But if you're like a superstar, we can absolutely move you forward.
Intrepid Broccoli: Right.
Astronomic Koala: Okay. Let's define a couple files here. Okay, so, say this is a web app. And we have our entry point as well. So what I want you to do is write me a program that takes in these files, and outputs the directory structure, including the files as well, in a specific format. This is a fun one. Yeah, like this would be a possible solution. There's also other solutions as well. So here's another one. So be like this. And yep, there we go.
Intrepid Broccoli: Right. Okay, so. And I'm, I was planning on writing this during this assignment in Python. If that works, it seems like in principle, this could be sort of like a bash question. But did you have anything in mind?
Astronomic Koala: No, I thought it's excellent. For this. I would say another good one is Java if you feel comfortable, but Python totally works for me.
Intrepid Broccoli: Okay, good. Yeah, I actually don't, not so good at Java. So maybe, maybe Python is better see here. So first of all, let me just put in here a couple of functions that I'm going to need, and it might. So let me I'm just going to put a function is Dir. And it'll take in a string, which is, which represents the file name. And it'll tell me if the function is a directory as opposed to a file. So it should return a Boolean. And I, there probably is a built in function that does that. So I'm kind of showing my ignorance here by not knowing it, but you know, I'm just going to assume that that that function exists. And ultimately I could write is file, you know, I mean, APA is, you know, is not directory.
Astronomic Koala: Okay, I'm gonna need to know that. And I'm looking at the format you guys need. Okay. Index asset okay. What is my input to this function? Is that the root directory as a string?
Intrepid Broccoli: No. So your input to this function would be the list of files because essentially, we want to parse that file system structure and then...
Astronomic Koala: Okay, good. That's, that's a whole different problem. Okay, good. I'm glad I asked. Okay, so let's see here. And, for instance, if I noticed that the four files, you've given me share a common directory, but that that needed to be the case, I'm assuming so there may be more than one. I guess. If you call the root directory, just slash, but there could be more than one directory on the level of directly beneath the root directory. Is that correct?
Intrepid Broccoli: Okay, so that's a good call out, it will actually make your life more difficult if it is, without giving too much away. So let us have anything under slash webapps.
Astronomic Koala: Oh, can you repeat that, please?
Intrepid Broccoli: Yeah, like, let's assume that everything is under the first like, in this case, it would be web app, but the first root directory would always be the same.
Astronomic Koala: Okay, everything is under, there's only one file in the root directory. Let's say that we care about. In this case, web app is that file and we can assume that there's no other.
Intrepid Broccoli: Yeah, like what web app would be the directory, though, right? I know. You said file web app would be the direct host.
Astronomic Koala: I'm sorry. Yeah, maybe I'm using incorrect terminology. When I say file, I mean to say, whatever the whatever the word is. that could be either a file or directory. I don't know exactly what word to use for that. I see.
Intrepid Broccoli: Okay. Just to be specific, though, let's assume that it's always a directory. Like there's always a top level directory. And it's always just...
Astronomic Koala: That's a good assumption to keep in mind. Okay, there's so there exists a top level directory and only one so there exists a unique top level directory. Okay. And I guess like just one very quick hint, because I don't want to throw you off here. Don't want to fix on that top level directory that doesn't change much like for you solutioning out, it's not productive to focus too much on that. It's just if it wasn't there, your solution might be a lot more complicated.
Intrepid Broccoli: Okay. Okay. That's interesting. Okay. Let's see. Okay. So this is kind of silly, but I know that I'm going to need a file to... Okay, so my input is a list of strings, right? Oh, yes, that's right. Okay. Oh, my keyboards going a little janky here, okay. So that'll be my main function. And it's just going to print right, it has no return value. Correct.
Astronomic Koala: Hey, can you hear me now? Yes, I can. Okay, cool. Yeah, you can just you want to return anything, just print it.
Intrepid Broccoli: Okay. So I'll have I'll make myself to myself a little function here that says remove initial character. I don't know if I end up using that or not, but it should be a string input. Hey, I'll put pass there. Okay, so print files is going to do that. Okay, let's see. Okay, well, because of the format that you've given me, conveniently, I can, I can start printing right away. So in other words, like, there's no need for me to delay any printing once I see the first line of the input will actually you wrote, yeah, it doesn't. So apparently, from your examples, it doesn't matter in which order I put the subdirectories. Right. Like, like assets versus versus will index is not a directory, but like, HTML could come before J S, or the other way around, for instance? Or do they need to be in a certain order?
Astronomic Koala: No, they don't have to be in anywhere. It's just arbitrary query shot.
Intrepid Broccoli: Okay, so this is this is kind of nice. So I can actually just start printing right away and I probably don't have to remember that much. I have to remember like the current directory that I'm in so maybe let's see here. Some might be something like finding a common root with a given file or something. Let's see here. So I get that I need to go down there. So yeah, so essentially what's going on here is I'm every line that I that I come across, I need to print a directory, sort of, I need to print a list of things that end up being a file. So if I look at the first thing, it says web app, J, S, C, J S, can you see that highlighting that I've done there? Yep. Okay. So that I actually did that as one thing. So really, I should think of it as I'm printing. The first three lines represent of the print output represent one thing, which is the C dot js file, and they come it comes, the printing format comes from an a list, each of which has like the path to that file. So think of the path to C dot j, s, for instance. Like a list a list of strings, which are journeys, okay. And plus, lastly, a file name. So, what I want to do is I want to make a function that says, def prints path. And it's going to take in a list of so I'll call it path, which is going to be a list of strings. And it's going to output none. And what it's going to do is, it's going to give it a list of strings, hopefully this is becoming clear what I'm going for here. So print paths of web app, this will be strings, web app, comma, assets. Let's say js, and because we were taking the other example, J S, comma c dot j s, we'll print these first three lines. So all that print task needs to do is sort of think docstrings needs three quotes like that. So I want to say just print the list print each string, on its own line, each indented only with dashes, I guess. Each printed with a with an extra indentation. So now, the what I need to do is when I get a new file is okay, so also I need to... this is interesting. Okay, so in your example that you gave webapps, let's like all of the files that are in HTML subdirectory are together. But I'm guessing that I cannot assume that that would be the case in general. Is that right?
Astronomic Koala: Yeah, that'd be right.
Intrepid Broccoli: Okay. So it might be worth doing a sort of a sort on the initial file, so that I can assume that now the thing that I would want to think about is, is there any way that that could bite me like if I do, supposing I sort the input, and I just say, you know, here is like, files equals list, sorted files. Is that going to come back to bite me somehow? In that... First of all, what's the problem here? It says undefined in list. Okay. 22 import list from typing. So is there any reason that that should not guarantee me that all of the files that are in a common subdirectory will be together? So I don't know. It seems like that would work. Do you have any objection to that solution? Ro that, you know that that step in the solution to sorting it like that? Are you there?
Astronomic Koala: Oops, sorry. I mean. Oh, okay. So this is kind of interesting. I see what you're doing here. Okay, I've never seen the solution. So I think what you're kind of doing is like I'm just trying to understand. Can I can I try to explain it one more time? Sure. The only one thing I would say, and this is something that trips people up commonly when they just think of like a simple solution is just keep in mind that you can't... You're not duplicating the parent directories for each one, like for HTML and Vita HTML, they're both just under HTML. And that's not printed twice, right?
Intrepid Broccoli: Oh, yeah. So yes, I agree. So what my plan was that, in order to determine what needs to be printed for each line, I mean, rather, for each entry in the the files list, so far, so good. So I'm trying to go from entry in the files list to what needs to be printed. So first, I'm going to take a sort of, you know, greatest common directory with the previous item in the list. And then that will help me determine, or the least common directory, or however we want to say it that will help me determine what to print. So if I'm looking at web apps slash assets slash v dot HTML, I can say, Okay, well, last thing that I did was print HTML. So I don't need to reprint these things here. And therefore, in order to what I'm going to send to the print pass function is is a singleton list that is just b dot HTML. Because of that information, now, if A and B did not appear, if they if between a debt HTML and B dot HTML, there was another file that lived in the J. S directory, for instance, that would kind of break my approach because they wouldn't be gathered together. And I wouldn't be able to look at the previous entry to determine what I needed to print. And that's the function calling sorted there. Did that help you understand better what I'm going for?
Astronomic Koala: Yeah, definitely helped me understand more. I'm just curious kind of how you're going to implement it. I will give you one hint, just to kind of simplify your solution, because it's still possible that this will work. But I think perhaps a simpler way would be kind of, to just parse this into some sort of data structure, and then that data structure will kind of like inherently remove any duplication. And you know, just one quick traversal of that will give you the correct answer. You're saying, Okay, that'll work. Okay. Though, if you if you feel confident this one and you want to do it, if it could still be okay, as well. So I'll leave it up to you.
Intrepid Broccoli: Um, well, I mean, it's just so naturally forms a tree, doesn't it? So it just makes sense to, to put things in a tree of some kind. A true, maybe we'll do it. We'll do it that way. Okay, so you recommend making a little class, so node and then we'll say that each node has a string. And we'll say def init self as string. self dot named name equals well, I don't know name is probably reserved term, isn't it? So I'll say self dot node name equals s. And I also need to it needs to have some children. SoI will say def add child and that will be self and s string. And then I will say self dot children. Let's say this about that. So if self dot children self children append node s, okay. And then I will say else self dot children equals a list containing node. Okay, so that seems to be that seems to make sense. This is just an n-ary tree. There's no limit on the number of children a given guy can have. I may have forgotten something but I'll so I'll go back and make it and then I probably won't need this print path function. So let me just, you know, comment that out. We'll just move everything to the bottom. So now let's just go into main functions. So that's print files of files, which is a list of strings. And it returns none. And then we'll say so the first thing we want to do is, I mean, really, our print files function should do only two things. One of which is tree is equal to build tree from files. Okay, and then it should do the last thing, which is print three of three. I mean, that's really the what essentially is going on. And why is it? Why is it undefined? Oh, well, yeah, I haven't defined it yet. So, of course, oh, gosh, this is this happens to me, I, I keep locking myself out of my computer accidentally. Okay, so now let's make a build tree. So let's say that build tree from nodes, well, files, which is a list of string, and it outputs a node, which is the head. And we'll do that in a second. And we'll just say another function, which is called def prints tree, which takes in a node which is the root of the tree. And root, which is a node and output none. Okay, and that will, will come, we'll figure out what that means. In a second. Oh, gosh, keep locking myself out of my computer. So what should we do? First, let's see there's build tree and there's print tree? How much time do we have? We are on 29 minutes here. So maybe not going quite as fast as I would like, but we will get it done. Okay, so build tree from files. What I want to do is I want to say something like, split it on this the slashes. So you know, I can I can extract this into its own function. If I were if I were a Python Jedi, I should know exactly how to do it. So let's say oh, it's cool.
Astronomic Koala: No worries, man.
Intrepid Broccoli: Parse, parse file name into lists. And it's going to take in a string path, which is a string. And it's going to output a list of strings. Okay, so we'll also do that in a second. But so print so build tree is going to say, for path in files. First, it's going to say list path as list equals parse, file name into list of paths? And then what don't you like about that? Local variables assigned to the never use? Okay, whatever. So now, I'm going to go through the list and add the node to the tree if it's not already there. So I should probably have a little auxiliary function that says add to tree, add node. Tree. And this is going to be roots node. And it's going to do nothing because it's going to modify it in place. And okay, so then I'm gonna say path has list equal to parts is equal to that.
Astronomic Koala: Or, I don't know item in pass as list. Well, actually, you know what, I, I should just pass the entire list into add nodes to tree because I'm not I don't need to go through all everything again and again. So why don't I just make it lists node. List of node. And then, but it's not going to necessarily be a root it's going it's called being like a path. So for item in paths list now I don't need to do this I should just say for paths and files. At this list is this and I'll say add node to tree which is passed as list and that's would really take care of it. Once I implement that function, and then down here it'll return... So let's say first of all. Yeah, I mean, this will actually do everything, I just need to make sure I have the root node available. So maybe... I don't know parse file name into lists. Or rather add node to tree could take in a root as well. So let's say root path is list. It's hard to say exactly what we want here. So obviously, obviously, I need to tell what tree I'm going to add it to at some point. So root node. And I'm going to need to create the root in build tree somewhere. So that needs to happen. So let's say root equals node, just blank string at first. And then in add node to tree, I might need to populate the root. So I'll need to take a make sure to check if the root is empty. Just for this, the root dot nodeName is empty. Okay, so let's get back in business. For path in files, add node to tree do that stuff. That seems like all we need in principle for that function. And now let's go down to print tree. So that means that we just need to do basically and I want to say at a I'm just making sure I'm saying it correctly. So pre ordered versus post order. And in order. It looks like we never we only want to print the leads, obviously. But actually, what we really want to do is a an inorder traversal. So basically, this is just going to be... traversed in order. Oh, actually I just need to make sure I'm saying the right terminology or so we want in this case, we want all the every item first and then its children. But actually, we want to first print the item and then go eagerly to the next the first child and print that and then that down and print that so that's interesting. Just I'm just trying to remember exactly what that order traversal was called traverse in. I should remember that in a second said traverse in..
Intrepid Broccoli: Yeah, know where you're going with that. It's pre order traversal.
Astronomic Koala: Oh pre order. Okay. So root children. Okay. So how's that going to go? It's going to say current node equals let's see, what we want to say is if not node does not root just return. So if I pass it none I want to return. And, but I probably won't be passing it none. I'm guessing as it turns out, so I'll say... now, this is interesting because I kind of need to remember how many spaces I'm indented downside because if I, if I so let's say print tree root node. So I'll make a print tree helper... which takes in well, actually, I'm not sure I need that. Do I so well. The problem is if I say a new line, it doesn't just take Right to the beginning of the next line, so I do kind of need to know the current indent. So that if not root return, we know that we'll pass in here, make it happy for a second. And we'll say print tree helper of roots, and the first one has indent zero. Okay, that's good. And it'll know to print the dashes and stuff. And so then upon print tree helper will say... Oh, do you want the characters with new line at the end of everything or not? Or not at the end? Or at the beginning? Does that matter to you?
Intrepid Broccoli: You know what, I'm not super worried about it. So yeah, it's totally cool.
Astronomic Koala: Okay, so print tree helper is going to say, first, it's going to say first print string, which I've just built spaces. So let's say spaces equals one space times in beds. And then I'll print spaces. So are like if spaces... Let's say spaces equal to nothing. And if invents spaces, plus equals that, and then I'll print spaces. And then I will say, and I mean, probably this should be extracted into its own little function. But we could do that if we wanted to. All right, now prints that stash. Now print the root dot node name, string, and there should be one. So we wouldn't, we shouldn't expect to run into the error where the root has no name, no name, unless you give me an empty lists, but I should probably check for that in the main file. So in the main function rather, so if not, files, just return, print nothing. Okay, and then here we're on print tree helper print and note name. And then also print a new line. And then for show child in root dot children we're going to print tree helper of child, comma, indent plus two, right, because we want to, you want to advance two spaces on each line as I understand it. So that makes sense. I think as long as there's only one root so we start with no spaces. If there's an indent do that. Each stack of the stack frame has its own space variable, that's when I print the spaces then I print the dashes then I print the node name and then for each child and print that and then I come back when I return. So I just forgot to print return and space that out a little bit to make it a little more easy to read. And yeah, that makes sense. So thing be calling if there's no children. Okay. Yeah, so any tips real quick before I just kind of finished implementing it I'm not going quite as fast as I wish I was but that's part of my thing I'm working on here so before I finish doing everything else do you have any tips or any input?
Intrepid Broccoli: No, I mean, I think it's going pretty well.
Astronomic Koala: Okay, good. Yeah. Great. Okay, I'll finish up. Okay, so I think I'm I print files functions done build tree. Is this done yet? So for passing file path is list is equal to parse file in tree, add note to tree I think that is good. Yeah, so now I need to make sure I have this print tree helper, that's good build tree, I need to make sure I have path as lists and add nodes to tree. Okay, so path is list is, I call it path, parse file name into list. Okay, so this one is basically just like this is something with Python string split. And I'll have to figure that out a second. That's probably the least important part. But important to get right. And then here, I want to say add notes a tree. Okay, so this is interesting. Now, I have a root node and I have a path to list node. So this is kind of fun. So let's see how exactly they want to do this. So if root dot node name is not root dot node dot node name equal to path zero. Because I shouldn't be passing it an empty path. I'm already I'm always getting some kind of path. Okay, so that's just getting that out of the way. And now, I want to say so when I add a node to a tree, I want to check if let's see. So for item in path, which is a list, maybe I'll remind myself that I'm it's a it's a list by writing it as path as list. Or item in past as list. I'm going to say current node... So first, we'll make the current node equal to the root. And then I'll say for item in passes list. Okay, yeah, so I just need to make sure I'm doing this in a way that makes sense. So. So my current node starts out as the root and the first item is going to be the root. So if I don't know if item, dot item is equal to current node, this is only going to obtain in the very first case, in the root case, so dot node name, fall, then I'll continue. Okay, now, if item is in the current node dot children, then current node equals okay, this is interesting. So if it's in the children I sort of need to get the art the index of it in order to reach it, don't I? So, you know, the children could be set. I don't know. That's interesting. So I might maybe make the trip maybe make the children have set it doesn't it's not really ordered. And that's kind of closing some extra difficulty on the problem. So I guess I'm kind of getting lost in details here. But because well...
Intrepid Broccoli: We have like about three minutes left.
Astronomic Koala: So yeah. Okay, just give me that that heads up. Yeah, for sure. Yeah. Okay. So current node is equal to I don't know how I'm going to do this. So current node dot children. Index of that will say in here that index equal to get index of item in current node dot children. And I forget how to do that in Python, which I should know. So we'll just say that index of X and l so... Okay. Second, current node that, and then I'll say, continue. But actually a need to... Yeah, that's fine. But if it's not in, it's not in there. I want to say, I want to say current node dot children, dot append node of item, actually not starting quotes, just straight up items. And then I'll say current node is equal to.... Again, I'm having get index thing. So this is kind of dumb, but I have to fix this. But I don't really have time to fix it right now. So this is good practice to not do dumb things in the future. So item current node, children. Again, we're doing this dumb get index thing. So current node equals current, node dot children, index. And now I continue. Okay, so that seems to make sense. Let's see what else is going on here. Sure, wish I had written it well enough, so that I was sure it was going to run now what's wrong with this path? Of passes? Lists? Yeah. Okay. Current roots on here. Oh, that's your cursor? I see.
Intrepid Broccoli: Okay, so I feel like just out of unfortunately, no problem. Yeah. Yeah, for sure. I'm actually stopping you a bit early, because like, I have quite a bit of feedback in it's not necessarily from it being from it being bad. It's, um, so let me just explain this. I've asked this question many, many, many times. And a lot of the solutions are, let's just say this is probably the closest that I've ever seen to what I myself would write, which I find quite interesting. Yeah, it's very interesting, I think me and you have a lot of the same coding styles. Like I personally love using like a lot of small utility functions and stuff, like what you're using, but I was able to get quite a read on what like kind of feedback to provide you for improvement as well. So let me let me just kind of jump in here. We'll make sure we can get this in before the 10 minutes is up. Okay, so before we jump into the coding stuff, let me just give you a few, like higher level things, I would say, try to stay higher level before you jump in. I think that's one thing I would have liked to see from you. And I think that comes more from like a structured approach. So at the start, just, you know, spend like two, three minutes asking clarifying questions, which you kind of did, I'm not gonna lie, like, I wasn't totally like, not impressed with that, but try to stay a bit higher level in terms of like, hey, what kind of data structures and algorithms can I use to solve this? And like, when you actually get, you know, this candidate algorithm, don't feel like you need to jump into the code to prove that it's right. Just like, even if you want to pseudocode it, not everyone likes that. But at the end of the day, I just kind of need to see you, like, show that your algorithm works on an example before you kind of jump into the code, if that makes sense. Okay.
Astronomic Koala: Yeah, yeah. Okay, so, so kind of feel it out with the interviewer and say, like, here's what I'm gonna go for, I'm gonna, I'm gonna describe to you in a few sentences, like my overall plan, and then or hopefully, in a few sentences, and then to see how they want you to go in terms of do you just want some pseudocode you want me to just start coding?
Intrepid Broccoli: For sure. And I think like, you know, concrete example for this one is like, let's say it took you like, three to four minutes to be like, okay, you know, a tree data structure kind of works for this. Okay, a preorder traversal kind of works for this. And then what I would do from there is parse the list of files like you would with your strategy. And then you know, have your tree and then just do a quick preorder traversal to make sure like, the output is right. And then at that point is like, okay, you know, I can jump in and just start bashing this thing out. Like when you're coding, you should be removing a lot of the ambiguity beforehand, so you're not like trying to figure things out on the fly is one tip.
Intrepid Broccoli: Okay.
Astronomic Koala: Yep. Okay, let me just look at my notes here. Doo doo doo. Okay, before, yeah, I guess before we jump into the code. Okay, another thing is think about optimizations before you code. That's a really good tip too, because sometimes you'll waste your time coding, and it won't be optimized. And it's like, it's okay to code. The brute force solution. Like you're not going to like, we're not going to be like, Oh, this guy's you know, coding the brute force solution. It's A total waste of time, but it's just moving to get the optimal solution. So the way I would think about it is like, run through the the time complexity, you know, maybe volunteer it to the interviewer, in this case, you know, it was order n squared for the tree, I probably would have asked you that as well, by the end, but, you know, kind of ran over time. Anywho. Like, what I would say is, just make sure that, you know, you're like trying to get some sort of optimization. And if it's possible, and I think you were getting there, because you kind of, I think I heard you mentioned, like, set or something. Yeah, that's what I was looking for. Right. So that would have brought it to order. And so yeah, my view is just kind of think through optimizations just very quickly before you code. Obviously, it's okay to tell me the brute force, but doesn't mean we always need to kind of code it. That's all. Okay. Cool. So, you know, concrete example, again, what I would say for this one is, it would have been good for you to realize that this was a trie data structure instead of a tree, because tree is the naive implementation. Yeah, okay. Realizes that it's a trie, like with saying, it's a trie, they just kind of, they just go, okay, you know, when I'm inserting, and I have to insert, finding the parent at each level every time to you know, insert the node, hey, you know, I can just use a map instead of a list, which I think is what you were getting at. Were like, a hash set or whatever. So yeah, yeah. Great to just call that out beforehand. Always a good idea. Do Okay, and then, so jumping into the code, see, like, I'm just kind of working against the clock here. It's always difficult cuz I gotta jump off, like, what's on? Just give me one sec. Sure. Okay, so number of different things. And they're not all bad. I actually thought your code was quite clean. Overall, I think you have a good coding style, maybe a little bit biased, because it's like mine. But essentially, what I'm saying is the best coding style in the world, no. But personally, I think your code is very clean, I would have given you positive data points on that I think your use of utility functions is excellent. Now, I'm going to throw in a little caveat here, and this maybe something that can help you. And it's kind of contradictory. So number one, feel free to use small utility functions, without necessarily implementing them. So I'll give you an example. Online 85 to 91, you probably lost between, you know, you last maybe two to three minutes, just trying to get that out. If you need done something like this honest to God, print with paths do an in depth. And then I would have just left until the end. And most interviewers don't care, because it's such a simple function. It's like, we know where you're going with that, you know, it's it's not a big deal. Yeah, whatever, whatever you want to do. And then you wouldn't have had this line 85, or whatever, it was just the line. But then I'm going to contradict myself here and say, be careful of using too many utility functions, because it's easy to get trapped in like trying to figure out the signature and this and that is your add node to tree one, I think it would have been better for you to try and implement that just in the build tree function. And then by the end of it, if you want to refactor into a function, that would have been totally cool. But it's actually a bit easier to just do it in the build tree function, in my opinion.
Intrepid Broccoli: Yeah, since it is the last, the last item in the build tree function, it's not really that bad to just implement it there. I agree.
Astronomic Koala: For sure. And it's interesting, too, because it actually has a timing concern in the sense of how it's kind of difficult to explain this. But essentially, you can be, you're modifying your pointer for the entire path, like as you go along in some of the model solutions, like I'll send you a model solution in the one after this potentially, but you have this current pointer that just starts at root on this on line 111. And you can easily just build a path of the tree by modifying current as you insert and it makes it a little bit easier than doing it in a different function. So my advice is, yeah, my advice is just do it in the in the central function, and then refactor after if you have time. Okay. Yep.
Intrepid Broccoli: So it's about being judicious in which things you factor out into an input into a utility function right away. Then knowing what's like, you know, core logic and what's just like some BS that you need to just everybody knows what you mean.
Astronomic Koala: For sure, I found myself before I kind of internalized this advice. I found myself running out of time because I was trying to implement too many small utility functions or definitely a balance though, because I live your utility functions made total sense. Like I think you nailed it at the start when you're Like, you're like, oh, we need to build the tree and we need to traverse it. Like that made total sense to me. I think that was awesome. But there's just kind of a balance. And I think you're a little bit too far into, like, making so many functions that it's going to kill your time.
Intrepid Broccoli: Yeah, that's a good point. And so one thing, that's something I should optimize, and as of right now, a lot of it is well, I think it is, you know, there's, it's some kind of a coding style, but also, it's like, it helps me think through it, if I'm like, okay, these are the two major steps, it's kind of like chunking it, you know what I mean?
Astronomic Koala: Definitely. And keep in mind, it's also like better for us to see you kind of get the right solution and then refactor, like, maybe not perfectly, you know, you run at a time after you refactor, you're like, Oh, crap, you know, I didn't get it perfect, rather than the reverse, where you're like one or two functions away from getting it. Like, I think that's a more ideal outcome. So my advice would be like, lean towards refactoring afterwards, as much as possible. But some sometimes, you know, it makes sense to do it first, like the the one who said like, okay, and then what else did I have here? Quick comment about just like explaining the entire time. So I like to tell people that, you know, you kind of get this advice where like, you can do like, Oh, you have to just explain yourself the entire time, you know, to talk, talk, talk, and more talking is better. I disagree with that, I think it's appropriate, if you do get stuck to like, if you're thinking style is better, like when you're just silent, it's totally fine to say to the interviewer, like, you know, Hey, man, I'm going to take five minutes to just kind of think this through, and then just be silent, that's totally fine. The caveat there, I will say is that I get the sense that you kind of are like a thinker on the fly, where you're almost like thinking while you're talking. So if that's the natural way for you to think just keep doing what you're doing. But if you're just doing that, you know, just to kind of show your thoughts, then perhaps consider my other advice.
Intrepid Broccoli: Yeah, that might be a good strategy to compress the time a little bit more. It's like, if I take if I allow myself, you know, maybe not, maybe not at the very, very beginning, should I be silent, but like, if I've been going for a little while, and maybe just allow myself a little time to just work and then come back and be like, here's what I just did all the blocks. That could maybe save me some time, because, you know, I think I'm okay at talking while I'm working. But I work a lot faster if I don't have to talk while I'm doing it.
Astronomic Koala: Definitely. And I think you're kind of nailing it. When you're thinking like timing. That's something I've struggled with as well. Keep keep talking one like, like, I'll say this, like keep timing high on your priority list for your practicing. Even if you go do leetcode Try and don't do it in a relaxed fashion necessarily try and like think through it as if you're in a real interview and focus on getting your timing as best as possible. Because I think you're still a little bit your timing is just a little bit offered Google.
Intrepid Broccoli: Yeah. I would agree.
Astronomic Koala: Wicked. Okay, I think that's the majority.
Intrepid Broccoli: So you're going to send me an implementation with a try, so I can see how that looks.
Astronomic Koala: Yeah, for sure. And you know what, man, it's actually very similar to your current solution. So it's like, basically, it would be your solution, maybe with a map instead of a list. And then oh, okay, that's about it. Yeah. And then just like a little bit, maybe, like simpler code at certain aspects. But yeah, it's basically like what you would have gotten to I think, if you have more time.
Intrepid Broccoli: Okay, great. Yeah. Awesome. prioritize timing. Thank you for that note.
Astronomic Koala: Yeah, no worries, man. Yeah, this was a fun session. Actually, I enjoyed this one. I have to take all I think that's pretty much the audio of my notes. But yeah, dude, I wish you the best in your real interviews. I think obviously, you have a lot of promise. Just work on the timing and the other stuff that I said, and I think you're in good shape.
Intrepid Broccoli: Thank you very much. It's been a pleasure. Yeah, take care. Bye.
Astronomic Koala: Bye.