Interview Transcript
Purple Brontosaurus: So I won't disclose my name, but I've been working as a software engineer for almost like six years so far. I spent some time working for Google and other like companies out here in the Bay Area. I'm your mock interviewer for today, so I just want to like, kind of give a bit of an intro and. Yeah, can you tell me a bit more about yourself?
Meta Slide Rule: Yep, sure. So I am a software engineer. I have been working for a year and a half, almost two years, fresh out of college and I'm working at a series B startup. But I have a Google interview lined up for like the on site. So I'm just prepping for that particular round. Yeah, okay.
Purple Brontosaurus: All right. I'm definitely wishing you best of luck. I've done on sites for Google. They are rigorous, but they are also passable.
Meta Slide Rule: Yep, okay, sure.
Purple Brontosaurus: And yeah, just to get some background, so you mentioned that you have one and a half to two years. So I take that you're targeting for like an L3 or L4 type of position at Google, is that correct?
Meta Slide Rule: Yep, that's correct. I'm Targeting for an L3.
Purple Brontosaurus: Okay, just clarifying. And yeah, what programming language are you most comfortable in?
Meta Slide Rule: I'm most comfortable in Python, so I would go with Python. I think I can pick Python 3 from this list.
Purple Brontosaurus: Perfect. Yes. Please pick a language that you're most comfortable in doing your development in. I am familiar with Python 3 and yeah, so just some, some heads up, like if you want to grab some water or if you need to like take a break, feel free to do so.
Meta Slide Rule: Yep.
Purple Brontosaurus: And also if you want to use pen and paper to help like crystallize or your thought process, feel free to let me know. So don't feel like you're constrained. If you want to toggle the whiteboard or set the environment to your advantage, you're welcome to do so.
Meta Slide Rule: Yep, for sure.
Purple Brontosaurus: And I'll try to follow along with you. So don't just feel like you have to be writing or if you even want to like dive into pseudocode, you take it how you want to evolve it.
Meta Slide Rule: All right. Yep. Love it. I think I'm ready. I see a toggle whiteboard here as well. So if I need to draw something to you, there'll be that.
Purple Brontosaurus: Yeah, I just Want to ask like you're familiar with the environment and all the setups, right?
Meta Slide Rule: Yep.
Purple Brontosaurus: Okay. All right, sounds good to me. Okay, so I'll be taking a problem from leetcode.com and let me know if you have or have not seen this problem so you can go to. Yeah.
Meta Slide Rule: Yes, I have not seen this problem actually. So. Okay, let me just go to the link.
Purple Brontosaurus: This is from Leetcode. It's called Cinema seat allocation. I'm going to copy paste the word problem description and yeah, I'll let you take your time to read through the problem and make sure that you understand it.
Meta Slide Rule: Yep. Thank you. I'll take some moments. So yeah, given. I'm also going to read it out loud just to be clear where I'm at. So I have reserved seats containing the number of seats already reserved. For example, if it's like 3 and 8 reserved seats at I is at 3 and 8 means that the seat located in row 3 and label with 8 is already reserved. So I guess if I were to imagine it like a 2D array, then at row three in column eight, that's reserved. Cool. So return the maximum number of four person groups you can assign on the cinema seats. So a four person group occupies for adjacent seats in one single row. So seats across like 33 or 34 are not considered to be adjacent. But there is an exceptional case on which an aisle, it's split split a four person group. In that case, the aisle split a four person group in the middle means to have two people on each side. Okay, cool. So what I'm counting is the number of the maximum number of four person groups I can assign. So in the example on leetcode I can see that there are three rows and then on the first row there's four in the middle and then on, on the second row there's also four and then on the first, sorry, on the third one there's also four. So I guess like on the second one, the reason that I cannot pick seven to ten is because it's not split in a two and two way. It's split in a one and three way. So then that is not valid and I have to go with the two and two option. Similarly, that's why I cannot pick from one to four and. Okay. And then for the last one. Yep. Oh, because I'm trying to go for the maximum. I also cannot go from four to seven. I have to go from two to five and then from six to nine. Okay, I can see it. All right. Yep. So I'm Trying to come up with a brute force approach. And so what I'm thinking is, so N here is denoting the number of seeds. So like I know for a fact that my array, let's say will be n times 10, right? Whatever n is, I would have 10 slots per seat. So let's say like this is my first. Sorry, I think maybe I just number it 1, 2, 3 and then go into 10, same for here, go to 10. So yeah, and then there will be more of this. So I can represent this as a matrix. And then for the reserve seats, for each of the things for each of the seats in here, I can mark it on this matrix somehow as taken. So let's say if I just have a bunch of slots like this, I can mark it accordingly on my, on my matrix. And then let's say if I were to mark it now, I could go through row to figure out how many, like what is the maximum number of four of a four person group? I can assign here. And then for each of the row I just do that and then add it to some kind of answer sum variable. And then in the end I just try to return this answer. So I think, let me think about the logic to try to pick from a single row. So pick from a single row. So I know that the row is not as simple as adjacent slots because the first three are divided from the next four and then divided by the last three. So let's say if. So let's say if like I need to see the available slots, but basically from 0 to 2 it's a different area. And then from 3 to 6 is a different area. And then the remaining, you know, like from 7 to 9 is also a different area. So I think, for example, let me take an example of the first row here. I was given 1 and 4. Sorry. So I think actually 1 and 2, 1 and 3. Is it okay if I take the example from Leetcode?
Purple Brontosaurus: Yes, it's okay to leverage the examples from Leetcode. I want you to use those examples since you have graphical understandings and because the minimal examples.
Meta Slide Rule: Okay, awesome. Yeah. So I think I'll just take the first example. It seems simple enough. And then so I know that this slot is taken. Let me just put a dot in here like an X. And then I also know that 1, 3 is taken. So it's equivalent to this. And then the last one, sorry, this one is taken. So then when I look at this, I think, I think one of the things that I could do is I could basically they're actually only, I think there are only like three maximum for rows. There are only three possible slots that someone could have. Right. So like even if everything is empty on this row, right. If, let's say if this row is not taken at all, I think the maximum number of four people group, maximum number of four people group is going to be three. And correct me if I'm wrong here, but it's because first of all the one in the middle will be what we focus on. So that will be one group and then the second one is from, basically from index one to index four. So that's another potential group. And then the third one is like from index, like from, from basically like the last, the last two of the middle and then the first two of the last section. So yeah, so maybe I can restrict what I'm checking here since I know that There are only 10 seats in a row. So maybe I can just do something like I make a, I have a loop and then I go through the four slots here and then I go through the four slots here. @ any point, if it's at any point. So basically it's like a loop of three iterations. So like a loop of three iterations. And at any point if it's, if any of these is like picked already, then I just moved on to the next iteration. So like I would start the iteration at index 2 and then at index 3 be because it's the beginning of this 4 seat like group and then at index, so sorry, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7 and then at index 7. So I think it's going to be 2, 3 and 7. I'm going to start checking and then yeah, in the case where like these three are available, then the maximum that I could have for a row is three and I would just add it to my answer variable in here if that's okay. So I think that's the brute force approach that I could come up with for this regarding like the space complexity, of course, because I'm trying to recreate this whole theater seating. It will be basically like n times 10, whatever the n is. And yeah, and then I have to loop through like this, but it's still less than n times 10. And for the time complexity I'm going through each row and then for each row I'm having three iterations. So that'll be like an O of N time complexity. Yep.
Purple Brontosaurus: Yeah, I agree that I like where you're starting with the brute force idea and I think you're definitely on the right track. I think you're like on the right track. One, one thing that I'd like to see us is if we can like take a bit of time to try to optimize for either time or space complexity and see if we can get away from having to do an O of N space complexity approach where N is the number of like sort of aisles, that it's a number of rooms. So if you notice like on line 25, N can blow up to 10 to the power of 9. So can we leverage like other variables or other constraints to cut down on, to cut down on the space. So it may either be like you may either say, take space from O of N to a better, bigger complexity or maybe you could cut down space and time by some constant factor or leverage a different variable. So it's A versus N. So let's try to think about that aspect.
Meta Slide Rule: Yes. So I realized that definitely I don't need to recreate this visually because I can just make a for loop through N. And then I know that Basically I have a 4i in range something and then 4j in range something. And then at this index, at this coordinate I and J, I could check if it's taken by checking against the reserved seats array. And maybe to optimize checking against the reserved seat array, I can also turn this into a set of coordinates for fast access. So that would be a way to optimize what I already have in terms of space complexity, in terms of temp complexity. I'm trying to think if there is a way for me to make this faster than a loop. Right now I'm more leaving towards like just laying out the, like basically having the structure in a for loop without having any extra variable to store space. And then when I have the coordinate check against this reserved seats and then I can continue with my loop of three iterations that I mentioned here. But yeah, like if this is the number of, this is the number of rows, then I would still at the maximum, like check for it 10 to the nine times. So also try. I'm also trying to find out if there is some way of doing this with faster, with a better time complexity.
Purple Brontosaurus: If I think one thing that I could say is, could you imagine a case where your cinema, like your movie is really unpopular and maybe only like one or two people are actually sitting in a really big cinema. So what would you. How would that kind of help you, like a case where you don't have that many movie watchers?
Meta Slide Rule: Oh, oh, oh, oh. I see, I see. Okay. So it's kind of like a sparse array thing. Yeah. So maybe I should focus on reserved seats here because the length of reserved seats is obviously way smaller than the length of like the number of rows. So maybe how about. What if I start with reserved seats? Like maybe I could sort it first or something by the number like by the row so and then by the, by the column so that like let's say if I were to have four three here and then maybe I can have like four six next. And I mean of course like one four and one seven will go first. So let's say if I were to focus on this reserve seats and sort it now I know that I only have to focus on two rows which is row number one and then row number four. I don't have to care about the rest. I could assume that it has maximum. It can give me the maximum group which is three. So yeah, in this case I think I only have to check for two rows instead of. Wait there. Sorry, I was wrong. This was the four. So in this case maybe I only have to check for two rows instead of all four of them. So yeah, maybe I should focus on the reserved seats here and try to go from there. And the sorting, it's going to take more time complexity. But I was just thinking that it would be way easier to check if something is on the same row according to the loop of three iteration that I have. So that's why.
Purple Brontosaurus: Okay.
Meta Slide Rule: Yeah, like just. I think yeah, it's better to check the reserve seats. But yeah, so I think that would be my rough approach. I'm also trying to think if I can like optimize it in any other way. But yeah, most likely. Actually I think I don't even have to sort reserve seeds, to be honest. I can just loop through this array and then I grab the rows that I need to check and then I think that'll be it. Like grab the rows that I need to check the number of seats, like the number of seats available and then for the rest, for the rest and I just add three because I know that they're all empty and maybe I can turn this reserved seats into like to a set for faster access. So in that case I think it would just be O of N with N being the length of reserve seats or something.
Purple Brontosaurus: That sounds like a good idea.
Meta Slide Rule: Yeah, like I think, I think it could work. So yeah, let me know if I should go over like some pseudocode or maybe I should start coding stuff like that.
Purple Brontosaurus: I think you should go with what you're Most. Most comfortable in. So if you feel more comfortable in pseudocode, go with pseudocode. If you want to get started. Dive into code. Dive into code.
Meta Slide Rule: Okay, sure. Thank you. I think I'll just dive into the code and maybe I could do dry run and go over it after. So I'm going to make a function called reservese and that takes in an array of, sorry, reserve seats or like I'm just going to call it seats. And then I know that this is a 2D array. So let me just make an array of what to start with. So I'm going to loop through seats. I'm going to say like for row and column in seats. I know that actually I think my array could be a set. I don't think it matters that it has to be a. I don't think it matters. It has to be an array. So I'm just going to say like for the row here, then I would just add the row into my set. So actually I should call it S not to be confused. And then for the columns, I think I do not care about it at this point. So then I have my start or like rows to check, something like this, some kind of rows to check. And then for the seats here I'm just going to have like seats set. And then I think I can do a set operation around the array seats. So this would be it. And then I would loop through my set of rows to check. So I'm going to say. And actually within each of those I only care about three things. So but that's the layer. So I'm going to say for a row in rows to check. So for each of these rows I have an iteration of three. So I'm just going to say for column in range I start. So basically or like four columns and maybe I will start with an array. So it will be zero. Sorry, not zero. So let me look at the index again. I'm going to start at index one, so that'll be one. And then the second one I'm going with is three. One, three and five. Yeah. Oh no, sorry, not five. One, three and I think is six. Wait, no, actually I'm right, it's five. I'm just bad at counting. All right, cool. So then now I have the row and the columns I'm going to make sure that for the next. So like now I have row and column and I'm going to make sure that for the next four slots it doesn't get taken by checking it against the seed set that I have here. So I'm going to say for I in range four.
Purple Brontosaurus: Okay.
Meta Slide Rule: And then I'm going to have the row and then I'm going to have the column plus I. So then if at any time this. This array. Actually it's not an array.
Purple Brontosaurus: Hold on.
Meta Slide Rule: I think I'm. I have to make it like this because it's divided by a comma in my. In my original array. So I think I have to say if row and column plus I is in my seedstead then I have to basically break out of this most inner loop and then continue with the next set of column. I think maybe there is some optimization I could do here, but I'm just gonna think of it simply as breaking out of it. And actually I think I need to have a count within this. So I'm going to say like okay, if it's in here, then I break out of my most recent loop which is this one. And then actually I shouldn't break. I think yeah, okay, I'm breaking out of this for loops. I think it's okay. Otherwise if it's not in the. It says if this is done then I will have to plus one to my count. Actually, yeah, I think breaking it. Breaking here will break out of this closer this loop. So I think I'm good here because in the end and then it will go on to the next thing. But I'm not sure if I'm counting correctly. It's all. But okay, I'll go over it later. So yeah, so that's the roast tech. And then I know the number of rows I have because it's given to me in the form of N. So let me just. I forgot that N here so that we like N minus rows to check. And then this with times three is my answer. So in the end I'm basically return C plus actually C cannot be here. So let me just put it outside. And then basically it's counting the number of slots in each row. So I think it would still work. And then in the end, basically I'm trying to find C plus three times N minus rows to check. Actually, is it three? Yes, I think it's three. So it will look something like this. I think maybe I should.
Purple Brontosaurus: I want to stop you for a second. I think that's a good question you just brought. Is it free? Do you think we can take a look at the problem description and verify and check if we're following the requirements?
Meta Slide Rule: Yeah, yep, that's for sure. So.
Purple Brontosaurus: So I think you're on the right track. But I Think we should take a look at the problem statement and look at what the ask is?
Meta Slide Rule: Yeah. Yeah. Okay, so maximum number. Okay, so I think first of all what I realized is that my reserve seats is one index. So I need to pay attention to that. Reserve seeds is one index instead of zero index. So definitely something you have to do. And the next thing is maximum of four person groups. I can assign.
Purple Brontosaurus: Just a second. I need a refresh. I got disconnected. Can you still hear me?
Meta Slide Rule: Yep, I can still hear you.
Purple Brontosaurus: Okay. I just need to reconnect.
Meta Slide Rule: Hello?
Purple Brontosaurus: Yes, can you hear me?
Meta Slide Rule: Yep, I can hear you.
Purple Brontosaurus: Okay, perfect. Yeah, it's a temporary. It's a transient failure. Let's get back to where you're talking.
Meta Slide Rule: Yeah. Oh, okay. So I realized that I cannot check for the middle part here. If I'm, if I, if I basically, if I decide to go with the first one, then technically, basically, if the if row, like if column two to nine is free, then the maximum that I could go with is two and actually not three. So it's kind of. There's a constraint here basically with the columns. So I think. Let me think about how to do it. So basically there's a constraint here with the problem because if section 1 and 3 is free, the max root return is 2, not 3. And the way that I'm counting right now, I'm actually counting three for it, which is wrong. So either I take the middle part or I take the two sides or two sides. So I cannot take three. It's not three for the, for the, for the case where all the seats are empty. So this should not be three to begin with, this should be two. And then, yeah, the way that I'm counting here is wrong. So I think I have noticed several things and so I think I'll fix these problems. So first of all is my index. And second of all is that for a maximum, like we can only take a maximum of two for a row instead of three, like what I said before. So I am going to look at this code again. So basically I want to make sure that if it starts from 0, from 1 and 5, then it has to be occupied. Otherwise like from 3 has to be occupied. Okay, let me think about this a little bit. All right, so rows to check. Okay, so I think, I think I can do two separate loops, kind of. It would still be the same thing, but it would just check them separately. So.
Purple Brontosaurus: Well, I have a question. Like, do we need like there are two loops, but how many like cases are we checking? In a sense, like how many configurations of four person seatings are available? You sort of talked about like a seating of like 2 to 5 and 6 to 9. What's like, are there. What are the other configurations? If that exists.
Meta Slide Rule: Oh, yeah. Like, it has to be blank from two to nine. That's it.
Purple Brontosaurus: Yeah, yeah.
Meta Slide Rule: If I want to. It has to be blank from 2 to 9. Which would already include the 4 to 7 being. Oh, yeah, which would already include the 4 to 7 Being blank.
Purple Brontosaurus: So, all right, there's three configurations. There's like 2 to 5, 4 to 7. And you mentioned, you mentioned that.
Meta Slide Rule: Yes. Yeah. So technically. Oh, so I, I see now. Like, so maybe I would just need to check basically a loop for. For whatever in range from 2 to. To 10, which is like, not including. But it's basically from 2 to 9, essentially. Like, so if it's all blank. If it's all blank, then I have two groups here, so I can add two to my count. Otherwise, like, otherwise, if they're not blank, then I need to check if. Or like have some kind of, let's say, have some kind of like, variable. Let's say, like, basically my variable is middle empty or something where I can basically also check if middle is empty. And then let's say when I get out of this, like, basically if I didn't add two and then middle is empty, middle empty is true, then maybe I can just add it to my account as well. So essentially I would have to check from column two to nine, but that will already give me the information on four to seven already. So, yeah, I think I could do something like this. And then, you know, like, maybe middle empty is set to false in the beginning, so it's easier for me to check. So in that case, I think I will just fix this code instead of this. For loop, I'm saying like for column in range to. Actually, I have to fix my index first because everything starts from one. So rows to check would be one and then okay, for row and rows to check. All right, I think I can still do this. So I would just say like 2 to 10 essentially. And then from 2 to 10, let's say I have like this middle empty. And I'm assuming that it's false to begin with. So now I'm checking. Like, if I'm checking if the row and the column is in my reserved seats or not. So basically, at any point, if. Let me think about it. So like, if this is in the reservation, then row and column is in reservation. Then this row and column. Yeah. Then Basically, I cannot add to. But I still have to check from. So I guess I, I guess like I, I'm. Maybe I'm thinking too much. I just need to check if it's in there.
Purple Brontosaurus: I think you're on the right track, but you're fixating too much on the single case of like the indexes 2 to 9 here, I think to get you to see you back on the right track. Like again, you mentioned there's three configurations of seatings which are index strategy. Like this, seats from 2 to 5, there's seats from 6 to 9 and the seats from 4 to 7, right?
Meta Slide Rule: Yep.
Purple Brontosaurus: And with this 2 to 10 approach, you know, like the 2 to 10 is a combination of 2 to 5 and 6 to 9, right?
Meta Slide Rule: Yep.
Purple Brontosaurus: So if you didn't have the 2, it's a.
Meta Slide Rule: What would.
Purple Brontosaurus: I guess a way to kind of steer you is like if you didn't have the 2 to 10 available, but you still have to check like other like configurations. What if you had to check the configurations individually? So say 2 to 10 wasn't fully available because someone is sitting at 8 or someone is sitting at 3. Right. Like you could have those two types of cases. So maybe if we think about checking groups individually, it could help you with checking the group. The scenario of the groups in totality.
Meta Slide Rule: Yeah, yeah, yeah.
Purple Brontosaurus: So what if we could like. Could we try to like decompose the problem into its constituent cases?
Meta Slide Rule: Yep. I think, I think maybe it's better for my thinking if I do that because I was kind of confused here. So. Okay, I think I. Then I would say like I would have three case, so then I would make three for loop in here just to have my three case to see, like it's left empty, it's middle empty and then it's right empty and then I can go from there. So the first one is from two to five. So I'm going to say for colon range two to six. And then the second one would be for column in range four to eight. And then the last one would be for the column in range instead of 4 to 8. That would be 6 to 10, right, 6, 10. So from this I can determine if the group can be made. So basically like, so if my row and column is in my set, then I know that I cannot do this, so I have to break. Similarly, if my row and column is in reserved seats and I have to break from here and the last one as well, then I have to break from here. But in the case that it actually managed to finish, I Think how do I say? How do I check for it? So I think I'm gonna. Let me think. So let's say I'm assigning that, like left is true in the beginning. So maybe like left equals middle equals right equals to true. So if I have to break, then at least I'll just toggle it to false. And then middle equals to false, and then right equals to false in this case. So then at the end, when I finish checking all of these, I can say that for this row, if left and right, then I know that for my count I can add two confidently. Otherwise, else if middle is available, then I can just add one. But yeah, I think maybe this will clean it up way much more. So I still have like the count here and I check for left, middle and right. So by default they are true. But if they cannot be made, then I switch to false. And I have an if statement here to count and. Hello? Hi, can you still hear me? Hello?
Purple Brontosaurus: Yeah, sorry, I got cut again.
Meta Slide Rule: Yes, I don't know if you caught the last part, but I was basically like making. I'm basically making like Boolean variables to check left and middle and right and default them to true. And then if they cannot be made, then I just switch to false. And. Yeah, so if there's left and right, then I just add two to my count. Otherwise if there's only middle, then I add middle to my count and. And then in the end I think I can just return basically the count or like I can add it to the count as well. Whatever the count already has, I added with 2 times n times minus rows to check, and then I can return my count. So I think this was my solution.
Purple Brontosaurus: Yeah, I think that this is on the right track, but I want to ask if you think we're missing any edge case scenarios, or if you could walk through. Through the. For loop structures and see if there's somewhere where you may be adding account, where you may not be adding account. So I could tell you, but I want to see if you can catch it.
Meta Slide Rule: Okay, cool. Yeah. So maximum of all. Right. For adjacent one in a single row.
Purple Brontosaurus: Yeah, because I think, like, the code is mostly correct, but I feel like it could break in some edge case scenarios. So if you can think about, like an edge case that you might be forgetting, it's going to help you.
Meta Slide Rule: Yes.
Purple Brontosaurus: With like a single row or with like a single. In a single row configuration. I don't want to give you an. It's not an edge case where you have multiple rows, but think about somewhere that you're not account a scenario that you're not accounting for.
Meta Slide Rule: Yep. So I mean, I'm thinking of like an empty row. I'm just like naming my ideas here, not testing on it yet. Or like a full row that'll be the second case. Or like a row where a row with two to nine filled up. Two to nine filled up. That would not be an edge case yet. So let me think about another edge case, 2 to 5. Or maybe if it's alternating. I don't know if I've checked for it yet. Like, I think it will still work in the case that the seats are alternating. So think four person group in the middle. So two people on each side, you.
Purple Brontosaurus: Know, kind of checking for that middle as a standalone case. Right, like Ellis middle, right?
Meta Slide Rule: Yes.
Purple Brontosaurus: Can you walk me through why you're checking the Ellis middle as a standalone case if not the left and right.
Meta Slide Rule: Yep. So I'm checking it as a standalone case because in the case where it's an empty row, then we go like, I'm not gonna, I don't, I don't think I can draw it here, but we're going to have 10 slots. And then I know that basically when, even when the whole row is empty, the maximum that I can put people in, like the maximum number of four person groups is only two instead of three. So that's why. And I know like two is a bigger number than one, which is why I checked for the left and the right first. Because if there is left and right, then I don't even care if middle is available because it already implies that middle is available and that's the maximum group that we can have. So if there is left and right, then I just add two, which is the maximum number of four person groups to this answer. And otherwise if. Because let's say if left is actually, I don't know if left is. Yeah. Or like if left is occupied on the first two slots and right is occupied on the, on like those two slots as well, then maybe middle is still available if it's not set to false here. So yeah, I know that I'm probably. I do have some overlapping parts I'm.
Purple Brontosaurus: Trying to give nudge you without giving it away. Maybe a good example is what would. What's a weird case where you can test a single person sitting in a row where your code doesn't do its counting correctly?
Meta Slide Rule: Single person sitting. Oh, oh, maybe like you plop a.
Purple Brontosaurus: Person somewhere and you're like, oh, I'm not accounting for that. Correctly, it's just a single person and you have 10 seats, right?
Meta Slide Rule: Yeah. Maybe it's somewhere in the middle, I think I know. Like if it doesn't check correctly. So maybe I don't know if. Well, because first of all, you said.
Purple Brontosaurus: Something right, which is somewhere in the middle. So let's use that.
Meta Slide Rule: Okay, so let me try to draw it out.
Purple Brontosaurus: You can use pen and paper, or you can use this notepad. I don't mind. Whichever helps. Yeah, let's think about somewhere in the middle of a single person.
Meta Slide Rule: Okay, I see. So I'll draw it like this. So let's say, like, I think in the middle, that could overlap with this. Oh, oh, wait a minute. Maybe here. So I think I can see why it's breaking, because obviously my left is not going to be present, and also my middle will not be present, but my right is still fully functional. So then in this case it still should return one instead of like zero the way that I'm doing it here. So I think I have to change my if statement here. So I would say all right. If left and right, then I add two else. If. Yeah, like else. If there is the middle or think about it. Because, yeah, if I take the middle, then okay, I assume that the middle is not broken, but then there is also a case where there is just left or right. Then in this case I'm going to add one. But I think this might still be wrong because actually maybe not. So, like left and right. In this case it will take these two areas. So this is for sure will be here. So if I go into this middle case, it means that it's only left or right. And in that case maybe I can just do. Maybe in this case I can just do an else and then. But it's not certain that I could add one to it. Let me think. So if it's not left and right, it might not be left and right either. Like, okay, let me think about it. So maybe if it's left or right, then I would still need to add one here and then if. Actually, so if middle, I would also need to add one here. So maybe in this case I need to check instead of checking for. This is kind of wrong to check, but I think I can do this. And.
Purple Brontosaurus: I need to you consider, like, nestedness as a way to help you. Sorry, Are you familiar with the term nested conditionals or nested expressions?
Meta Slide Rule: Yes.
Purple Brontosaurus: Do you think that could help?
Meta Slide Rule: Yeah, I think that could definitely help. I could do an elif here and then an elif here, I think. Yeah, so I'm thinking that let's say, like, if, if three of them are true, then I don't care about, like the case where middle is true. I only care about left and right. So it would still work. And in this case that I'm trying to present here, left would not be. Basically left and middle are dead. But then, because I say left or right, right should still be available. So then I could add one. Other than that, I think maybe there is, because, like, let's say if I were to put it here, so now I know my, my left is dead, but then my middle and my right is alive. But in this case I would only return one instead of two. Right. Because. Sorry. Hello?
Purple Brontosaurus: Yeah, I'm still here.
Meta Slide Rule: I think I accidentally toggled the whiteboard. So in this case, I think if I have this case, the area that I'm highlighting, I think we only want to add one in in here instead of, instead of two, because we have four people and we either pick the four middle seats or we pick the one to the right. So in this case it's still just going to be one because we're not counting the number of ways I can assign. So I think, I think this if else statements will work. Yeah.
Purple Brontosaurus: Okay. I think it's almost there, but I think that's the case where, like that edge case that you have highlighted. Well, it's an I feel like if else. I think what is if else if? Like if the if fails, the else if evolves. But I'm not sure if. I feel like in a lot of programming languages, like two else if cannot evaluate consecutively. Oh, is that correct? I'm not always sure, but I feel a bit guarded about that. It's okay. Maybe in Python, if one of those else evaluates, it breaks out. I don't always know, but I feel like you're on the right track and I don't want to get too bogged down here. So what I want you to do instead is to walk me through test case examples. So if you could take. If you could walk me through one of the examples, like one or two examples from above, or create your own examples and show me how you'd be going through the code.
Meta Slide Rule: Yep, I think I could do that. So I think maybe I'm going to use this example that I have down here. Yeah. And regarding the elif, maybe I could opt to return early. That could also be an option since I only want to pick one from here. But I mean, I think the Elif in Python is not going to be run. Like if it picks one, it will not run into another. I think it would work. I'm going to pick this case where I only have one reserved slots, so it would be at. So this is one. So I think I only have one row. So let's say like my N is equal to 1 and, and then the reserve seats is 1 3. So this is going to be what I have for my case. And for this case I'm expecting the answer to just be one, because even though I have like all the remaining seats, I cannot pick all of them. It's either these four or these four. So expect one. Okay, I'm going to do a dry run. So I think my n will be 1, and then my seats that are taken will be 1 3. So that'll be a 2D array. So I have to do 1 3. And then the rows to check is just a set. And then after I go over this seats here, it says the rows to check is like maybe I can make it two, just to make it clear, maybe just one first. All right, so the rows to check here will give me basically just the first row. So it's going to be one. So this is my set, my set which is have one in it. And then. Sorry, it's on this line here. Yep. And then for the seed sets, I'm turning this array into a set for fast access. So it's going to look like a set. And then with 1 and 3. Yeah, cool. So my account is zero. Now for the row and rows to check, it's going to be one. And then I have left, middle and right set to true. So now I'm going from 2 to 6, which means I'm checking 1, 2 and then 1, basically everything. So like 1 2, 1 3. Actually 1 2, 1 3, 1 4, 1 5. All right, so 1 4, 1 5. So I have these four slots and I'm checking if it's in this seats and I do because 13 is in there. So because 13 is in there, I set my left to false. So at this point my left is false, but middle and right is still true. Oh, sorry, I keep toggling in something. Well, yep. And then for four and. Sorry.
Purple Brontosaurus: Yes, continue.
Meta Slide Rule: Yep. So now I think for 4 and 8 there's some overlap here, but it's like 1 4, 1 5, 16 and then 1 7. And in this case none of it is in here. So I never set middle to false, it would still be true. And then for the last one it was still the same. So in this case only the left part is false and middle and right will be true. So now I go into this. Now I go into this check. So my left and right is not both true. So then I go to the next one. It is left or right because it's either false here and true. So it will go here and then it will add count to be one and then. Oh, I think I shouldn't add this in, actually. I don't think so. I think it's okay. But my rows to check is a set, so I think I have to take N minus the length of rows to check here for it to be exact. So now I have my. When I go to this line, my C is 1 and I'm trying to add it with whatever like 2 multiplied by the number of rows minus the row that I have to check, which in this case, since rows to check is a set, I just turn it into like get the length. So it's one and it's one minus one. So it's zero. So it's just one plus zero equals one. So I think in this case it return.
Purple Brontosaurus: And theoretically speaking, if I toggle the configuration so that you had 10 rows but only one of those rows was occupied, how would that change your answer? What would you. For C in that case?
Meta Slide Rule: Yeah, for sure. So let's say like now like. So like at the end of this, my count, it was still one, but now if I were to have 10 rows, then it would be one plus two times 10 minus one. So that would be one plus one plus two times, not like one plus 18. So I think that'll be 19 slots. Yeah, so I think because it's 19 slots, because I have one for a row, but then for the other. Hold on, I think I'm a little confused. But yeah, I think for the other nine rows, each of them have two, so that would be 18 and plus one, that'll be 19. So yeah.
Purple Brontosaurus: Yep. I think you're on the right track here. Okay. And do you want to briefly go over the time and space complexity of your approach?
Meta Slide Rule: Yep. So I think yes. So I think for, for the space complexity, I still have to create a set, but since basically I'm basing the set off of this array seats here. So it will be the number of elements in the seats. That's what I'm going to have for my space complexity. So number of elements in seats. And then for the time complexity it will be because I'm looping through each of the row that is present in the seat. And then, and then of course I'm doing these checks. But since like it's, it's been limit. So I would say the time complexity would just be also the number of elements in seats. So I think in this case I have the same time space complexity because the check for if this coordinate is in the set is O of 1. And then even though there is some overlap in this for loop, it's an order that I know it's at most 10. And I'm doing it here like 12, just checking 12 slots here. That's a fixed number. So I would say this is my final space and time complexity.
Purple Brontosaurus: Yep, this sounds reasonable to me. I think that this looks good. So like basically like if C was equal to S, we have a space complexity, but it's in linear time of S and linear time complexity approach as well.
Meta Slide Rule: Yeah.
Purple Brontosaurus: Okay, so we still have some time left. I do want to ask like if there's. If you want to like make any optimizations or you can see places where you think you would clean up the code. Like if you were to put this in a production grade setting, what are some things that you would try to do? So like in an interview setting we tend to make code more concise. But if I like reviewed your code or if I was concerned about code quality, what are some checks or modifications that you'd make?
Meta Slide Rule: Yep. So I think so my first observation is that this part from line 87 to line 100 is very similar to each other. So maybe I could make a helper function that helped me that returns whether this range is true or false, whether I can have seats occupied in this range. So I would have a helper function like say can range or is range available or something. And then I would put that code from line 80, 89 to 102. It looks oddly similar. I'll put it into this helper function and then this would take output a boolean. And I think that would help me greatly clean up the code because for the column here, I only care. I only care about it when it's in this range and then in this range and in this range, basically I can just assign three variable to this helper function and get my answer. And I think I can keep this piece of logic in here. And I think two is also like a random variable that I just made up here. But I could make it a constant that is like the maximum number of seats. I could grab for an empty row of groups. I could grab for an empty row and Then assign it here at the beginning or something like max groups per row and then assign it to 2 so at least it's not too random. When someone see that I'm adding two here and then I'm thinking of this. So like rows to check and then for this set, I'm not sure if I could clean it up further but.
Purple Brontosaurus: Probably I'm just curious like what you would, what you would do in such a setting.
Meta Slide Rule: Sorry, can you repeat that? It was.
Purple Brontosaurus: I just want, I just want to like sort of delve a bit into your brain and see what type of modifications you'd make. But I do like the suggestions that you like took a look into like the constant for what seems to be random and putting a modular function.
Meta Slide Rule: Yeah. I mean I also think that maybe if it's not 10, if it's like a bigger number then that but like, but then, then the problem kind of changes because it's not a group of four anymore and it's not 10, then I think I need to somehow have the mesh variable and know where the partitions are. But that's like a different, like it's a generalized but way different problem then.
Purple Brontosaurus: Yeah, I see. Okay. I guess another way that I could kind of stress test you a bit is if we had to develop a locking posture for this reserved seat, what's some information that you'd log if you had to do like analytics or you wanted to like take a look at trends over time with your seat reservations.
Meta Slide Rule: I see. So like if I want to look at a TAM series of my seat reservations or something like that.
Purple Brontosaurus: Yeah, like say an end customer or like an internal team member comes and tells you, hey, I want to have you output data or just any type of messages or outputs that indicate that help me parse out or graph statistics. What would you do? It's open ended. There's no right or wrong.
Meta Slide Rule: Okay. Yeah. So basically I need to store data somehow, but I also need to know what the data would look like for me to even be able to graph it. So like let me think. So are we trying to track the count of like the groups of four over time or are we trying to track the, the seats that are reserved over tam?
Purple Brontosaurus: I guess that's a good question. Let's say the groups of four.
Meta Slide Rule: Okay. Okay, so I see. If we're trying to track the group of four, the maximum group of four. Yeah. Then maybe in this case I think, I would think that saving the count is not enough. Maybe I want to have a more granular view of where those seats could be. So I think in here I just saved the count, but maybe I could also save the index range of where they're available, which is like for example, if I pick left and right. Well, yeah, or like, maybe I, maybe I return like some kind of enums that let people know which part could be taken. So, so then maybe like for this, for this one I'm doing since, since left is taken, it could be middle or right. And then I would do middle and then right. Something like that. But then I'm assuming that we would track like possible empty section. Right. Like with the definition of section being either the four sheets in the middle or the two and two. But yeah, like, so I would say like, maybe if I were to break it into like two and two versus like, sorry, versus. I think it has like autocomplete but versus like group of four. Then maybe I could say like, maybe I could say like, oh, for each NN2, N2, let's say it has like left versus right. So maybe for this I could say what are the possible slots? So if I have middle and right, I would say middle, which is four. And then I would say like two times two on the right. So something like this just to have a visualization.
Purple Brontosaurus: Yeah, I think that makes sense to me. I can see that you're on the right track. I think I was thinking more like from like the context of a logging posture and like seeing the frequency that we run into left into each type of assignment, if that makes sense.
Meta Slide Rule: Oh, oh, oh, I see like the frequency of assignment.
Purple Brontosaurus: Yeah. So that way if an end customer comes and it's like, how often do you run into each edge case scenario, they could like sort of do a grep or some type of fuzzy index search and they could see, hey, I ran into left and right at so and so frequency. Or I ran into only left bookings so often Or I ran into the middle booking only so often. And by getting that logging posture, I could crunch the data and try to see like how a company could evolve its boarding structures or its boarding algorithm.
Meta Slide Rule: Oh, I see.
Purple Brontosaurus: Yeah, but that's okay. This is open ended and I think you're on like a good track here with this enum idea which is also returning like the sections that were taken or the sections that were like occupied. The sections that are taken. That's another good like formulation.
Meta Slide Rule: Yeah, I mean I was going the enum way because I think like this is just a count, but if we want to identify the bisection or like something More granular than having enum would be more useful.
Purple Brontosaurus: Yeah, that's fine. Again, so I think that we're almost over time or we are over time. We're at the mark of one hour and four minutes. So I'm going to give like a couple minutes for like Q and A. But before I give like I like to give feedback verbally in mock sessions. I think verbal feedback is. But before I give you feedback, I want to hear from you what you think you did well and then what you think you could have done better. So let's start with what you did well from your. From your side.
Meta Slide Rule: I think in this case when I first saw this, I didn't do it before so I was a little scared. I couldn't do it at first. But after going into the example I was able to come up with like a rough brute force solution and I think that was good. And I think like at first I was able to talk about my time and space complexity. So like and it was pretty clear in my mind. So I think that was the good one. But what I could have done better, definitely make more edge case examples. I didn't think about edge case much because I was very worried with getting the solution down first and trying to do a dry run. And then I guess this for loop kind of trips me up a little. It was not too confusing but I was overthinking that. Oh, maybe I don't want to have a duplicate check here. But since it's also just two items is not bad like so maybe I was too focused on like the too detailed like stuff. Yeah. But overall I think that's about it.
Purple Brontosaurus: Okay, that makes sense. Yeah. My verbal feedback is similar as well. I think that you did really well on this problem. Personally I think like it is leaked medium and I really like it because so I was given it personally in an interview in the past too for another. And I also. And I think it's good because it's a real world scenario that forces you to read a word problem, parse out a word problem and put up a solution. And a solution isn't like overly complicated in terms of data structures. The complexity is in sets or even in hashmaps. So it's actually more of a test of how you handle a real world problem with constraints. So the handling of constraints and even knowing how to leverage sparsity to get to a more optimal solution, it's a good problem for testing how well someone can optimize their algorithm to be. To take less to take your operations.
Meta Slide Rule: Yep.
Purple Brontosaurus: I think like, overall you did really well. I think like, if I had any suggestions, there's an edge case scenario thinking. So I noticed that the way that I tried to nudge you more was to really think about the edge cases.
Meta Slide Rule: Yep.
Purple Brontosaurus: And as well as like also kind of thinking about, I think what I mentioned, like the idea of sparsity or the idea of leveraging like other constraints. It's to really look at the problem statements and to see like the information that you can use to your advantage. But I mean overall I don't have like strong negative feedback. I have mostly positive feedback. Like you have code. I'm fairly confident that if your fruit doesn't leak code and maybe made some modifications, you can get this to pass. In fact, after this interview ends, I want you to put this on leetcode and get this passing.
Meta Slide Rule: Okay.
Purple Brontosaurus: I think you did well with reasoning about your time complexity, your space complexity. You got it to really efficient solutions. I think your Python code is readable and it's very concise. I really like the conciseness of your, of the rules engine and the way that you handle and the way you handle your algorithm. I really like how you were able to tweak your approach as you better understood the problem. So initially I noticed you had some struggles with the left equal to middle equal to right Boolean expressions or the rules engine from 107 to 112, but you also got out of it. So it's not like you were stuck on it fully. Eventually, maybe after some nudges and your own thinking, you were able to figure out your way through it. So kudos to you on that as well and just general persistency throughout solving the problem. Yeah, I also make really thinking about your approaches like you were thinking about you. Even though you didn't go through sorting, you did consider sorting, which is, which is a good like, which is a good thing to think about. And yep, you're also think. And you did some really good thinking with the empty row scenario. So really understanding the empty row scenario helped you in this problem where you had two seats, where you had like you eventually you figured out, you figured out you're not supposed to return three times the number of like empty rows. It's supposed to be two times the number of empty rows. So you got that too. Yeah. Overall, I think your performance here is really good.
Meta Slide Rule: Okay, thank you. I was a little concerned because, like I thought in 45 minutes I have to solve like two medium or something or maybe more. So I was like very concerned about TAM as well. Yeah, but, but, but I don't know, maybe for the interview is only one question per.
Purple Brontosaurus: Per 45 interviews. You could get like one medium, but the medium could be taken in a way to really stress test you. So you can't necessarily say, like, just because I only got like one medium means that I'm, like, underperforming.
Meta Slide Rule: Oh.
Purple Brontosaurus: I mean, it is the case that, like, when you usually finish fast, like you would get like two mediums or something, or you get like a medium and then you wouldn't be expected to solve the second one. You just be expected to explore it a bit, if that makes more sense.
Meta Slide Rule: Right, Okay, I see.
Purple Brontosaurus: Yeah. I mean, I was able to stress this to you in some other ways. So we had some remaining time and I did ask you, like, how you would change a code or like, what is. Or like that question about like, like stakeholder or customer.
Meta Slide Rule: Okay.
Purple Brontosaurus: And yeah, I really like how you also typed out and laid out your thought process and how you visualize the problem. So that was done really well too. So I was able to follow along and understand your thought process. You're really good at technical communication.
Meta Slide Rule: All right, thank you.
Purple Brontosaurus: Well, I'm wishing you best of luck and yeah, I'll give my feedback and get back to you.
Meta Slide Rule: Thank you. I'll try to run this after the call right now. So.
Purple Brontosaurus: Yep, thanks for the problem. We can also connect over LinkedIn afterwards. All right.
Meta Slide Rule: Yeah, I would love to. Thank you. Thank you so much. All right, you have a good one. Bye.
Purple Brontosaurus: You too. Bye.
Meta Slide Rule: Bye. Bye.