# Recordings of mock interviews with Google engineers | Anonymous Technical Mock Interviews | https://coinselected.com

Sergeant Koala

: Hello ?

Intergalactic Avenger

: Can you hear me ?

Sergeant Koala

: Yes, am I loud enough ?

Intergalactic Avenger

: yea, I can hear you.

Sergeant Koala

: okay, great yea. It was delirious at me. It was telling me I was n’t forte enough.

Intergalactic Avenger

: indeed, are you familiar with the chopine and how it works and everything ?

Sergeant Koala

: Yes, I have done one of these before, so this will be my second one.

Intergalactic Avenger

: approve, well I hope this one goes adenine well or better than the stopping point one. So, I see that you ‘ve already picked C++, bold move. I like it. so, I ‘m precisely going to dive right in with a technical question, unless you have any other questions ?

Sergeant Koala

: no, go right ahead.

Intergalactic Avenger

: so, this is going to be kind of an algorithm thing. The theme is you’re kind of writing an AI for some sort of 2D map game, where you have a grid. I ‘m merely gon na draw out the power system here. So you’re going to have this 2D power system that you can sort of gestate. And, you’re going to have your status somewhere on that grid. And let ‘s just say there will be these coins strewn about in the space. You ‘re going to want to collect these coins. So you’re moving around on this grid and you’re finding these coins. thus, let ‘s start with something pretty basic and let ‘s fair say given the positions of all of the coins in the grid and your own stead, find an algorithm that will find the closest matchless. And let ‘s merely say for purposes of this exercise, let ‘s barely use the Manhattan distance. Let ‘s merely say you can only go up, left, polish, right. thus for exercise, the distance from `x`

to `y`

, which is `(2,1)`

to the mint down at `(1,3)`

. We ‘ll precisely say that distance is 3, which is one left and two polish. Does that make smell ?

Sergeant Koala

: so basically the distance is just the remainder between `x0, y0`

and a mint at `x1, y1`

. then it ‘s fair wish `(x0 - x1) + (y0 - y1)`

. Something like that ?

Intergalactic Avenger

: Yup, precisely.

Sergeant Koala

: And sol you’re telling me that I know the location of all of the coins, I have an array of their locations let ‘s say.

Intergalactic Avenger

: Yeah, let ‘s define a couple of classes here to help this along. So we ‘ll merely create a class `Point`

which will have `int x,y`

. And let ‘s say that what you’re trying to do is return the `Point closestPoint()`

given your military position and a vector `Point`

, which is the coin positions. You ‘re going to return the position of the mint which is closest to you.

Sergeant Koala

: all right, I ‘m assuming we have some sort of builder for `Point`

?

Intergalactic Avenger

: Ah, correct yea. Or you can write one. however you want.

Sergeant Koala

: Let me so, so my input is the vector `coinPositions`

. Okay so, I get my position and a vector of their positions and I need to return a coin that is closest to me. Well actually they ‘re public so I could just say … I could just put those at the bottom once I figure them out. Okay, and then I would equitable return `result`

at the end. Okay so, in terms of developing this algorithm, two things initially come into my beware. obviously the simplest solution is to do the algebra for each point and keep a run distance. so presently the closest one is `7`

, I ‘ll calculate the distance to the next one. Oh it ‘s 6, so I ‘ll replace it or oh it ‘s 9, so I wo n’t. And then probably along with that shortest distance I ‘d keep a prevail index. The shortest one is the one-third index in the vector presently. And at the end I ‘d equitable grab the values from the third one in that vector and then I would return that. The other idea, which may be sort of overkill, I mean you can do a width first search and that would return the rate of the closest mint. But given that we already know the locations of the coins, that would probably not need to be that complicated about it.

Intergalactic Avenger

: approve, let ‘s try the simple one precisely so we ‘re on the like page.

Sergeant Koala

: Okay, so `for (Point p : coinPositions)`

so I ‘m fair going to itteratate. I have to change this into a for loop with an one in subject I need the index. I probably will, because I will need to change it from the index. Let ‘s do `int xDistance`

, `int yDistance`

, and the `xDistance`

is going to be equal to `yourPosition.x - p.x`

and then `yDistance`

is peer to `yourPosition.y - p.y`

and then `totalDistance`

is peer to `xDistance + yDistance`

. That ‘s reasonably much the algorithm that we talked about in terms of calculating the distance. And then nowadays that we got the `totalDistance`

, we ‘ll start out with … I ‘m trying to think about if I want to subtract them the other way. For case of the case of I ‘m at `(1,1)`

and the other ones at `(3,3)`

. That would give us a negative number for each of them, and we do n’t want a negative distance. But of course it could be the other way. It could be `(3,3)`

and `(1,1)`

and then I did it the other way. So I think I ‘m gon na take the absolute value of each of these, because that way I get the actual difference between then, and it ‘s always going to be a positive number. And once they ‘ve been absolute respect ‘d, I do n’t need to do it for that one. And then I ‘m going to define up here `int shortestPath = 0`

. That ‘ll indicate that it ‘ll be the length, so that will be that. And then `int shortestIndex = -1`

at the moment, because I do n’t have one. I ‘m going to change this `for(unsigned int i = 0; i < coinPositions.size() i++);`

. because `size()`

returns an `unsigned int`

and otherwise the compiler will complain about that. And then the first thing I 'll do is I 'll grab that `Point p = coinPositions[i]`

. I 've got that. And now I can determine if I want to use this distance. `if (totalDistance < shortestPath)`

. Oh that 's a problem, `shortestPath`

should not start out at 0. I 'll have it start out at `-1`

to indicate that we do not have the shortest total distance. `if(shortestPath == -1 || totalDistance < shortestPath)`

. And then I will say that `shortestPath = totalDistance`

and `shortestIndex = i`

. `shortestPath`

was my overall unretentive path and `totalDistance`

is the one I calculated here. so `shortestPath`

becomes `totalDistance`

if `totalDistance`

is shorter than current `shortestPath`

or if the `shortestPath`

is uninitialized. So that seems like that would work, and then ... Yeah, we missed a bracket there, so we 'll get that bracket there indeed these brackets match up and those brackets match up. then after I 've gone through all of the points, I should have the shortest distance. then I would actually want to declare short distance as these two ... Those need to be outside of the for closed circuit or they would go out of scope, which would be cockamamie. Use them late, which would be bad. And then, that 's adjacent to that. And once I 've gotten out of this, `shortestIndex`

is truly the thing I care about. `result.y = coinPositions[shortestIndex]`

. This is all constant time. And then yeah, I precisely return solution. I think that should work. Let me try an example. For example, in this case I 'm at `(1,1)`

and coin at `(3,3)`

and `(5,5)`

. Well I 'd go through, and I 'd first have a coins at `(3,3)`

and so I 'd calculate the `xDistance`

, would be `myPosition.x`

, which is `1`

minus `3`

, so I 'd get `-2`

, so I 'd get an `xDistance`

of 2. `yDistance`

would be `myPosition.y`

, so it would be `1 - 3`

again. I 'd get the absolute measure to be `2`

. So the total outdistance would be `4`

and then I see `shortestPath`

is `-1`

, so that would get set. And then I 'd go through and the `(5,5)`

would yield a rate of `8`

, which would be greater than the total distance, and therefore that would n't change it, and then it should go down here, and then yea. So that should work.

Intergalactic Avenger

: Looks good. I 'm good going to create a little ... I 'm going to take that case that you gave, and I 'm going to ... And let 's see whether this can actually run. And then I 'll say `Point result = closestCoint(Point(1,1), coinPositions)`

. You 're at `(1,1)`

?

Sergeant Koala

: I 'm at `(1,1)`

, yup.

Intergalactic Avenger

: And then we 'll put `coinPositions`

. And then we will `cout`

result.

Sergeant Koala

: I think we might need another ...

Intergalactic Avenger

: Okay, lashkar-e-taiba 's see how this works. I do n't think we need that anymore.

Sergeant Koala

: Do we not need that anymore ? Do n't we need a `;`

after the classify ?

Intergalactic Avenger

: Oh regretful, yes. You do need a `;`

after the course.

Sergeant Koala

: Do you want me to go ahead and run it ?

Intergalactic Avenger

: We need a `;`

after this one excessively possibly ? I do n't know.

Sergeant Koala

: I do n't think you need it after `main()`

, I think it 's just classes.

Intergalactic Avenger

: Oh no, I mean the builder here.

Sergeant Koala

: Oh, so actually this method `Point closestCoin()`

is not in the class. I think it has to be in the class, does n't it ?

Intergalactic Avenger

: No, I do n't think then. Does it ?

Sergeant Koala

: I 'm used to sticking the definitions into the `.h`

file and then this would all be in the `.cpp`

charge, so I 'm not wholly sure what the rules are if you stick it all in the same file. Let me barely run it.

Intergalactic Avenger

: Let 's see what happens. Oof ouch. Okay, well.

Sergeant Koala

: Missing terminating quality.

Intergalactic Avenger

: Oh well that 's fair for this. That was that line, that 's easy.

Sergeant Koala

: It's still upset.

Intergalactic Avenger

: This is a pointer. That was my erroneousness. `vector`

is not declared, so we need to add vector.

Sergeant Koala

: I think I just did n't name something so that 's what those first 5 are.

Intergalactic Avenger

: Oh woah, what barely happened ? indicate alternatives. `vector`

was not declared. It wholly was declared.

Sergeant Koala

: I think you have to reset it. `Point`

was not declared in this setting. `Point result`

... Oh that has to be capitalized, that 's the problem there. Error `coinPosition`

was not declared in this scope. Oh I put an `s`

on it, it probably should be ... No, that should be the same.

Intergalactic Avenger

: Oh no, it 's misspelled, yeah.

Sergeant Koala

: Where did I misspell it.

Intergalactic Avenger

: right hera, `posisition. In `25`

. So `23`

... Yeah.

Sergeant Koala

: Oh this is the issue.

Intergalactic Avenger

: yea, and I think for these ones. here 's where autocomplete in truth helps. They should get that for `CoderPad`

. That 'd be cool.

Sergeant Koala

: You hit the reset button and then hit run.

Intergalactic Avenger

: Yeah, there 's inactive a couple of `positions`

misspelled. I think in `yourPosition`

, there 's an extra randomness in `line 25`

Sergeant Koala

: `yourPosition.x - yourPosition.y`

.

Intergalactic Avenger

: It's stead without the randomness.

Sergeant Koala

: phosphorus o mho one t one o n, right ?

Intergalactic Avenger

: yea, so there was an extra `s`

in there, but I got rid of it.

Sergeant Koala

: Oh o, great !

Intergalactic Avenger

: No matching function ... Oh, yeah you have to give ... Alright, thank you `C++`

. We 'll just do this then. Complaining that there 's no 0 argument builder. Alright, that 's fine.

Sergeant Koala

: Okay, and then the survive thing it 's huffy about is error `coinPositions`

... I probably misspelled that again.

Intergalactic Avenger

: Yeah, I think it 's good a copy paste with that extra s. And I think besides `shortestIndex`

. Oh, that 's how it was actually spelled before.

Sergeant Koala

: So it returned `(3,3)`

, but this is propose parentheses around comparison, so it good wants ...

Intergalactic Avenger

: That 's not a big deal. Okay, all right. `(3,3)`

, there we go. Oh, and one other little thing, I think it wholly works in this case, but the individual vertical bar is actually `bitwise or`

. And then what it 's going to is it 's going to take the leave side as an integer, and the correct side as an integer, and do a `bitwise or`

of those two integers. And that 's fine, in this case it actually works. But it 's kind of taking advantage of the fact that a `boolean`

gets turned into a `0`

. Yeah, approve, looks good.

Sergeant Koala

: And so I 'm not wholly aware of ... Like in Java, the `||`

is a legitimate or, is that besides a coherent or in `C++`

?

Intergalactic Avenger

: Correct.

Sergeant Koala

: Okay, so if I want to do a logical or, I do that. Okay, that 's good then. Yeah, that seems to work. Do you want to write some other test cases ?

Intergalactic Avenger

: Oh, no, no. I think we 're commodity for that one. so now we 're going to crank this up a notch. So first doubt is : What 's the runtime of this algorithm ?

Sergeant Koala

: all right. Well, it 's going to be proportional in share to the act of coins obviously, because it has to iterate through every single coin. So initially, let 's call the number of coins `n`

. There are `n`

coins. And then, it 's going to have something besides to do, hmm ... I guess it does n't very matter where they are on the board because I already know their locations. And careless, I mean unless there 's ... yea, american samoa long as they fit within an integer in terms of ... Yeah there 's a constant time sum of time it takes to run the calculations. You know, because it 's distance minus these couple of lines of code here. So that 's going to be constant time. so I guess this algorithm would run in `O(n)`

time where `n`

equals the number of coins on the circuit board.

Intergalactic Avenger

: Okay, excellent. so, let 's say that this is a very big display panel with a lot of coins on it. Is this going to be a good algorithm for finding that ?

Sergeant Koala

: No, because you're iterating through every single coin. My initial thought is that if I got some massive board, I would want to possibly cut out a sub-board, like a `10x10`

to start and see if there is anything within that board. besides I think breadth first search would look more and more golden as the display panel got bigger and bigger, because it 's good going to start at `x`

and it 's going to look at the squares that are adjacent to `x`

and then the squares that are adjacent to those square and it will stop a soon as it finds a square. So it 's going to stop and only hit one mint and if there is a mint relatively nearby, that could be a set faster than computing the distance between it and a million coins or something.

Intergalactic Avenger

: correct. Okay, sounds good. then, let 's say, just kind of diving into this tradeoff a little moment. Let 's say that it 's a in truth large board but there are very few coins on it. So you mentioned two algorithms already, one that is the search where you look around in a physical way, and then there 's the algorithm that you implemented. So which one of those is going to be good in the event that you have a in truth big circuit board with very few coins in it.

Sergeant Koala

: all right, what do I know about the positions of the coins ? Do I have any idea where they 're located relative to me ?

Intergalactic Avenger

: No, you just know it 's a adult board and you know there 's a few coins.

Sergeant Koala

: o, well I 'm going to assume that the coins are possibly on average half way across the control panel away from me, something like that. particularly possibly a little bite further because there 's sol few of them. And so, I 'm going to have to go a retentive direction and the cost of breadth inaugural search expands outwards. Like, if I was in the middle here on this square. I would have to do all of the squares around me and it basically expands corresponding to the come of sphere it 's covering. therefore, in that case I would imagine that the coin algorithm would be better. I mean you said there are n't very many coins, but even if the board were full of coins, like every single square was a coin, then that algorithm would take, let 's say the circuit board was `n x n`

, it would take `n^2`

time because it runs proportional to the number of coins, and there would be `n^2`

coins. But that 's not the situation, there is massively less than `n^2`

coins, there are a few coins. There might still might be a million of them, but there might be a million of them and there 's ten billion squares in the grid or something. And the breadth first search is going to take something proportional to ten billion to find the coin, possibly it has to search half the control panel around me, possibly it takes it five billion. So the coin algorithm I think would be better in that case. I mean the one I already have would be better.

Intergalactic Avenger

: The foremost one. Okay. sol, you 've touched upon a very matter to point. There are cases where it 's neither good for either one. There 's still a distribute of ferment that needs to be done. You talked about this one that 's a million by a million wide and there 's a million coins on it, there 's no easy way to find it. But one of them is clearly going to be better than the other. sol, let 's precisely say that all you get is the positions of these coins. And you do n't know how adult ... I mean you know, I guess we 'll say you know how large the grid is. How would you choose dynamically which one of those algorithms to choose. So let 's say that you basically are told that you want to find the closest mint. And you're given this information of the size of the grid and the positions of the coins. But it 's a general problem. sometimes you're gon na get a grid that 's got tons of coins on it. They 're very densely packed. And sometimes you're not. And you're gon na have to find some way to choose between the two algorithm.

Sergeant Koala

: Okay so I know the size of the grid and I know the number of coins and their positions. well, it sounds like it 's kind of in a hash table and when the hash table gets excessively full moon it stops working properly because you get besides many collisions. It sounds like I want to develop a proportion or concentration factor. This density divisor should represent the issue of coins per grid feather. indeed something like `coins / numberOfCells`

and beyond a certain bespeak, if it 's very dense, then I would want to use the width first search because there 's credibly one finale by and correspondingly because it 's so dense, there 's a batch of coins. But if it 's identical sparse and there are n't very many coins relative to the numeral of cells, then I would want to use this algorithm that I wrote out.

Intergalactic Avenger

: Okay, that sounds identical fair. So let 's grok into this proportion merely a small bit. So the number of coins of the number of cells, and you will define some kind of arbitrary ceaseless that that will be over or under in terms of your density to pick one or the other.

Sergeant Koala

: I do n't think it should be arbitrary.

Intergalactic Avenger

: Well I guess, yeah. I guess you would have to find that somehow. And I have n't given you much means to pick that number. But one interview I have is, is it that you're going to want some ... Are you going to want to have it so if `density < lambda`

, then you do algorithm one `else`

algorithm two. But this is one way to do it. But is this the formula you're going to want. I guess the interrogate is, this is setting up a analogue function where there 's this linear kinship between the lambda and the density and what point you have this flip.

Sergeant Koala

: I think I see what you're saying. so as the grid gets bigger, tell me if this is n't where you're going with this. As the grid gets bigger, the breadth first search is going to perform ill, not regardless of how dense the power system is. obviously, if every single hearty is filled with coins, then no matter what the size of it is, the width first search is `O(1)`

. But, generally as you have a higher concentration level, there 's still going to be more outer space. My intuition is that lashkar-e-taiba 's say that we take two cases, one where there 's a `1,000`

squares and then one where there 's a `1,000,000`

squares. And let 's say that in both of them, the coins to cells ratio is `1/4`

, so there 's one coin for every four cells. now if we assume that the coins are randomly distributed, can I assume that they 're not classify of clumped up or anything like that ? then, careless of how big the overall grid is, there should be a coin about every `4`

cells, which means that my width beginning search should have the same running time regardless of how many cells there are. I guess the difference is that the running time of my default option algorithm in this lawsuit would be much worse because this is going to mean that there are `250,000`

coins whereas this means that there are alone `250`

coins. therefore while the breadth first search should on average have about the same performance, because it 's going to have to go about `4`

cells, the cost in the uninitiate algorithm permit 's call it gets a lot larger. So we want to include a factor here that represents the fact that the uninitiate algorithm is more expensive regardless of what this ratio is.

Intergalactic Avenger

: o, very good ! And what 's the proportion ehre. so, as the size of this power system increases and this concentration factor stays the lapp, how does the size of the primitive algorithm grow versus how does the size of the search grow ?

Sergeant Koala

: I 'm going to change this, I want to change `c`

to be the number of coins on the control panel. So that 's `O(c)`

. And then I 'm going to say that north equals the full numeral of cells. indeed much times they say `n^2`

which is the length of the course by the duration of the column. I 'm precisely going to say normality equals sum issue of cells. And I think from this exemplar we can tell that as I increase the act of cells a thousand fold from a thousand to a million, that besides increased the full number of coins by a gene of one thousand. And so it looks like the increased cost of the uninstructed algorithm is proportional to the total number of cells. then if we increase the board a thousand fold, it increases the cost of the naive algorithm a thousand close up, given the like concentration.

Intergalactic Avenger

: So that 's excellent intuition, and nowadays I think you 've convinced that merely looking at that lambda is not necessarily going to give you the good choice because it works well for some sizes of the boards, but not others. So how are you going to adjust that ?

Sergeant Koala

: Okay, so I 've got the density is less than lambda, let 's say lambda is something like 0.8, whatever it happens to be. And then, well I want to think about the absolute cost of the ... I know the absolute price of the uninstructed algorithm. I want to figure out the absolute cost for a given size of the width first research algorithm. So if I have a thousand squares and we 're dealing with the one one-fourth, then the cost of width beginning search is going to be four, and that was besides true with the one million squares, it 's besides going to be four. My initial reaction to this is that it seems in most cases that the breadth first search is going to end up being better. But in terms of determining it ...

Intergalactic Avenger

: well, if there 's a million squares and there 's three coins, the other algorithm is surely better in that shell. So there is a cutoff.

Sergeant Koala

: That 's true, I 'm looking at it as `1/4`

or `1/8`

.

Intergalactic Avenger

: Yeah, you're surely right that as that coins per cellular telephone number stays the same, that much more much, and as the dining table grows, it surely becomes more and more likely that the search algorithm is going to be well. But there decidedly is a shortcut.

Sergeant Koala

: so if my concentration is `1/4`

, `density * n`

is the total cost of naive, right ? Because the cost of width first gear search equal ... I feel like it 's the inverse possibly of the concentration. so if it 's `1/4`

, yeah it should good be the inverse of the density. therefore if `density * n`

is less than inverse of the concentration, then I would choose that. So lashkar-e-taiba 's double check this. so for example, there 's a `1,000,000/3`

coins and the inverse of the density is some bantam little thing. I think that 'll work.

Intergalactic Avenger

: Yup, there you go ! No, that 's actually good ! There 's only one bantam man there that ... so you have `density * n~ < 1 / density`

. Can you rewrite that so it looks a little easier.

Sergeant Koala

: You still want me to write it as 1/ density, or ?

Intergalactic Avenger

: So that 's decidedly correct, so is there a little bit of algebra we can do here to make that a fiddling moment ... I mean this is very minor points, but um ... sol look at how concentration is defined.

Sergeant Koala

: That 's going to be, let 's call it `c/n`

. `c/n`

is this thing. And I suppose I could besides make the `n`

's are the like. If I multiplied both sides by `n`

, then this `n`

would ... No, no, no ... It's `1/c/n`

which is the same as `n/c`

I believe.

Intergalactic Avenger

: Yup, and then what 's this concentration here.

Sergeant Koala

: And this has an `n`

and this concentration is besides `c/n`

. so `c/n * n`

, those `n`

's cancel. so then this is `c < n/c`

I guess.

Intergalactic Avenger

: One other multiplication that you can connect to that.

Sergeant Koala

: I mean I can multiply both sides by c and say `c^2 < n`

. Like that ?

Intergalactic Avenger

: Perfect. And you can see here that you 've basically got the runtime of your algorithm on the two sides. So the runtime of your naive algorithm was `O(n)`

and the runtime of your early algorithm is on the other side.

Sergeant Koala

: The number of coins ?

Intergalactic Avenger

: No, the act of cells.

Sergeant Koala

: No, I think `c`

was the count of coins on the circuit board and `n`

was the numeral of cells. What happened ? We did something ... ?

Intergalactic Avenger

: right yes, yes, yes.

Sergeant Koala

: `n`

is the sum number of cells, `c`

is the entire number of coins. Or did I change these and possibly not change it here ?

Intergalactic Avenger

: Oh, I think it actually is the other way around. Because here they 're both with `c`

. Anyway, amazing. very effective. now. One more piece that I 'm going to throw in here, this is again going to be not then much about the tease, but about the methodology. So lease 's say it 's not good you who is on this board. You have some competitors. And your competitors are besides going after the lapp coins. And if they go towards a coin and everyone moves at the like speed, and if they get there faster than you, they take the coin and you do n't get anything.

Sergeant Koala

: So am I wanting to try to go to coin ... ? So there could be a lot of coins on this dining table. Are there a draw of opponents, or is there fair one opposition ?

Intergalactic Avenger

: Well, I mean in the most general common sense, there could be any number of each, but as we 've seen, the relative number and the proportional size do play a boastfully function of which kind of algorithm you want to use. But let 's barely for sake of discussion to get started, let 's just say that it 's a board of this size that we have at the bottom, and that there 's a minor handful of opponents that are besides competing with you for the coins.

Sergeant Koala

: all right, well I initially think I do n't want to go fro coins that are far away from me, correct ? so, I think I might want to ... I could basically sort my tilt of coins by their distance from me. And then I could go through and calculate how close each of the coins is to an opposition and it gets complicated because you might want to think about the fact that if there 's a coin that 's in truth close to an adversary, but is relatively far away from me, and it 's the closest coin to me, then he might go for that mint and then I could go to a coin that was closer to him, because I know he 's not gon na ... There 's this mint that I want to go for is 10 squares away from him and is 15 squares aside from me, but there 's a coin that 's only 5 squares aside from him in the other management, so he 's credibly going to go for that mint, so I can still go for the coin that he would differently get. So that 's one matter that would make it complicated. But in terms of a simple first job, I think I would just get the coins that are closest to me and sort the coins by how close they are to me. And then I would look at them and see how close each of them is to an adversary and possibly provide an equal slant. I could do two things. One is that I can provide an peer burden from me to the mint and the distance from an opponent to the coin. alternatively, I can eliminate any coin that was closer to an opposition than it is to me, assuming that they might go for it and take it before I go for it. The distance from the coin is order `3`

for me and it 's only `2`

from the opposition, I 'll eliminate that coin assuming that they 're going to get it and I 'll find basically the shortest path to a coin where I 'm closer to it than an enemy.

Intergalactic Avenger

: Okay, that is an excellent begin. then, you have this setup here. So you said that you're going to eliminate any mint that 's closer to an opposition than it is to you ?

Sergeant Koala

: That was my initial think yea.

Intergalactic Avenger

: then in this earth, you get barely this coin on `line 87`

here. That 's what you get because the other people are closer to the early coins.

Sergeant Koala

: buttocks they only go for one coin and then they 're sort of sated or something ?

Intergalactic Avenger

: Let 's merely think about it in terms of a single one. Everyone gets a coin and then you move on to the following map, just to simplify it. sol in this case, every coin is closer to an opposition than it is to you. So you do n't win any of them outright. But, in terms of this kind of sating as you said, they 're sated by the two coins that are closest to them, and that leaves this one devour in the corner open to you, because they 're not matter to anymore.

Sergeant Koala

: approve, well I guess what I can is I could calculate, this is going to sound in truth computationally intensifier, but I can calculate the closest coin to each opposition and assume that they 're going to go for that one, and then I can eliminate that mint from my tilt, and then I could barely of the coins that are left, choose the one that is closest to me. now the one change that immediately pops into my mind is that when I calculate the coin that is closest to them, I could check and see if I 'm closer to it, because then I could just get it away from them before they could get it. But other than that, I think I would calculate the coin that is closer to each adversary, and assuming that I 'm not closer to the coin than they are, then I would good eliminate all of those coins, then I would choose the coin that is closest to me of what 's left.

Intergalactic Avenger

: okay, so I see that. But what about this one. See if I can move this guy down one to make the map a little easier. So you said you pick the coin that is closest to each opponent and then you eliminate it from what you have access to. thus from that algorithm, this mint is closest to opponent number one, but this besides closest to opponent number two here. So you would only end up eliminating this one coin from your research.

Sergeant Koala

: It's an iterative summons, so I would iterate through each of the opponents. Through each of them, I could calculate the presently closest coin to that one and then eliminate it, so I do this guy, I calculate the closest coin to him, and then I would eliminate it. So that would be gone. And then I do this guy, I 've already eliminated that coin from my tilt or datum structure, so then I would calculate the closest coin to him given which coins are left. now obviously if I wanted to make this actually comprehensive, I could try and figure out ... There 's a situation where I calculate this ridicule, and I think he 's going to go for this coin that is closest, but actually there 's another person who is closer.

Intergalactic Avenger

: Right, I was good going to say that like what order are you ... That would work if you are traversing this in this ideal order. But if you had unintentionally picked this guy first, you would have said oh, his closest coin is this matchless over here and then actually that would n't have been the correct choice because another opposition who you would have seen former was actually closer.

Sergeant Koala

: Yes, so I mean, this is in truth going to hurt the guide fourth dimension, but what you can do is you could go to a detail opposition, find the closest coin to them. You then have to check all other opponents and see if any of them are closer. If none of them are close, then you would say this guy goes for that coin and gets it. otherwise, you would take the early person who 's closer and say, no they go for the mint and get it.

Intergalactic Avenger

: right right, so you're getting closer. Sometimes it 's a short difficult to come up with the claim answers here. Okay therefore, let 's say we have this apparatus. You start with this opponent. She is the closest coin, and even you are going to give that coin to him, even though, he was n't matter to in your mint, evening though he is closer to yours, he is placid not matter to in it, because he has one that is flush closer than that.

Sergeant Koala

: Okay, I think I need to for each play, calculate close coins to them. And then, I need to iterate through the players and check if there is a player close to my desired mint and is that coin their closest coin. therefore for exemplar, let 's say I 'm starting on y. Or I can even do it on myself. so I 've calculated out the closest coins to everybody, I say here 's this mint, I wish one on this function would be closest to me, like this one over here probably. so, let 's say that this one was further away. thus I start with this coin because it 's close to me and I 'd say, there is a player who is closer, and it is his close coin. Because it is his close coin, because he is closer, and to be actually sure, I would have to check that no one else was closer than him. therefore I 'd have to check that for `Y`

, all of the early ones are n't closer. then I would say, he is going to eat this mint, so I ca n't go for that one. So then I have to get my future close coin. `Y`

has been removed because he is sated as we said, and then I would say, ohio but this one is `Y`

's closest coin, and he is closer than me. so because it is `Y`

's closest coin, we know he is not going to go for another mint, he is going to try and go for this one and he is closer than me, so he is going to win, so I ca n't get that one either. And then these two are sated, so then I would say the adjacent close coin for me is this one, and by now I 've eliminated all of the other players, so I would n't find another player that was closer than me, indeed I know I would be able to get it. So I would go for that one.

Intergalactic Avenger

: Okay, yeah, no that 's estimable. I think that will work. I think the typical way you would do this, and you're truly near, for each player, calculate the closest coin to them, and then you sort by their distances. And so you know the person who has the shortest distance to their desired coin will automatically get their coin. And that 's actually the only greedy thing that you can say at that point, is that given that group of people and the coins, the opponent or the person, it could be you or it could be one of the opponents, the person who is closest to their coin is going to get it. And then there 's rather something else you can say that at sharpen, because there 's all these wyrd corner cases and gorge. then then you remove the player and you coin, and then you have to repeat the wholly thing over again. And then you have to find their closest coin over again, now that there 's one less coin and one less person. And then you have to keep going down until you are the person who is closest to their desired coin.

Sergeant Koala

: And that has a lot better running time than what I proposed because if I 'm checking if there 's a player who 's closer to my craved coin, this whole step is going to take a bunch more time than credibly getting the group of people for a given coin and eliminating the person who is cheeseparing. As I have to calculate the closest coin to each player and then, yeah that makes sense.

Intergalactic Avenger

: yea, and there 's no flying and easy way to do it. They 're all sort of computationally intensive. If you want the on-key and correct optimum answer, you ca n't get around the computational complexity. Okay, nice, amazing. That was it, that 's all I got, did you have any questions for me or any thoughts before we take off ? I 'll put some notes in the platform late, but did you have anything before I go ?

Sergeant Koala

: Yeah, no, I mean, it seemed like a good interview, I liked the short grid that you drew, and yea I mean I 'm just practicing interviewing obviously for job interviews, so if you have any suggestions you want to say to me now as opposed to writing them down, I 'd be glad to hear them. Otherwise it was estimable, thank you.

Intergalactic Avenger

: I 'll fill out some more information, but in general, very well done. The lone thing, and this is sort of a minor thing, is that if you are comfortable with other programming languages, they tend to be a little easier for these types of problems. so `C++`

, there 's a certain ... It's nice to know that you have confidence in it, and it 's decidedly like a lower level language than something like `Python`

or `JavaScript`

or evening `Java`

or something like that, but the thing is that there are a lot of details, like this unharmed thing with looping through the align, like that 's three letters in python, you know ? It's all superintendent, extremely easily whereas, there is a distribute of remembering, like delay, it 's called `size()`

and all of this kind of stuff. That 's in truth my entirely comment. I used to do a small spot more `C++`

scheduling, and I have done interview questions in `C++`

and I find that I end up spend unnecessary mental department of energy just trying to get the stupid `C++`

code to compile, than I am on focusing on the algorithm and the proficiency, and all that kind of stuff. sol yea, I do n't know if you have another lyric that you're comfortable in that is a little sting higher level, but that can be something that is for a batch of these coding challenge style questions.

Sergeant Koala

: Yeah, I suppose `Verilog`

is not a adept answer. so, I mean I 've written the most code in `C++`

and `Java`

. I have done a little bite of `Python`

, but I feel more ... I 'm a scholar right now, and partially of it is `Python`

is something that I 've done a little bit on the side, but the courses ... I 'm taking two different courses right now that use `C++`

right now, so it 's kind of more in my mind mighty now than early farce.

Intergalactic Avenger

: Yeah, that makes sense. And you decidedly do want to stick with something that you're comfortable with, because the other position you do n't want to be in is you saying that you have familiarity and comfort in a certain terminology, and then you do n't you remember how to do something basic, like how do you get the element out of an array, or how do you get the respect for the key in a map. And if you do n't have that truly down glib, than that besides looks a short bit bad. so, decidedly # 1, stick to what you're most comfortable with. then I would decidedly say going into it, specially with `C++`

, you're going to want to decidedly have all of your basic containers down, like vectors and sets and maps and all that kind of stuff. Just like how to insert, how to get elements, remove them, that kind of thing. That kind of material is laughably childlike in things like `Python`

and it 's a little more involved in `C++`

, but if you have it down and it 's in your fingers, like I know precisely how this works, then it should be good very well.

Sergeant Koala

: yea, my approach path to `C++`

was that I 'm going to use this for my interview terminology, and I 'm in truth going to nail down all those little details, and I 'll get it to the item where it 's jumping off my fingers like that. Yeah, that was kind of my opinion procedure.

Intergalactic Avenger

: Nice, amazing.

Sergeant Koala

Read more: About Witter Coin

: Yeah, thanks for taking the meter to interview me, I in truth appreciate it. It was a big question.

Intergalactic Avenger

: yea, good I hope you enjoy the rest of your even.

Sergeant Koala

: Have a good even, bye bye.

Intergalactic Avenger

: Alright, take worry .