Live data from Hacker News

I had to give a wrong answer to get the job (2017)

dewitters.com

201–210 of 409 posts

Re: I had to give a wrong answer to get the job (2017)

#201

I was in a job interview several years ago and I was given the following prompt: "You have a database containing locations with their corresponding latitudes and longitudes. We want to be able to input an arbitrary latitude and longitude and have the program return all locations within a radius from that point from the database." My initial reaction was to say "I would use a GIS library/API", but the interviewer want…

I would have just as stubborn about the spherical-to-planar issue. IMO it's easy to illustrate by pointing out an extreme example: two longitude lines can be feet apart near the poles (ignoring the intersection aspect for simplicity) and miles apart at the equator. If someone doesn't understand that... I don't know what to say.

Re: I had to give a wrong answer to get the job (2017)

#202

I bombed an interview at a game company because I gave a right answer that I couldn't get them to understand. I don't remember the exact problem they wanted me to solve, but the answer involved a dynamic collection and they wanted it to grow with constant time complexity. They were probably looking for a linked list. But I said I'd use a dynamic array because those have constant time when averaged over a series of ap…

Interestingly, you can use scheduling to make a non-amortized dynamic array. Your probably know this, but for other commenters who do not— Keep two arrays, of size n and 2n. Initially the first has capacity c = n/2 and the second has capacity 0. Reads go to the first array. When you append, append one element to the first array, and copy two elements to the second array. By the time the first array is full, it has be…

This is dangerous, but if well documented and understood it might be okay. Some data might contain unique things (for argument's sake, say a std::unique_ptr). It can get tricky since you need to know the implementation details of everything that gets inserted and it's ownership behavior, since elements can be kept at two places. (A copy in array n and one in 2n.)

Then there is the fact that you basically make every insertion 3x as costly. You better have a good reason to need this given the additional complexity and caveats.

As for the original interview question, there are systems where an occasional longer pause is not OK. Personally, I think that sticking to your gun must have come across as being stubborn and unyielding and maybe not ready to admit errors. As an interviewer, and for having worked with people who always think they're right and inflexible, it would have been a red flag.

Re: I had to give a wrong answer to get the job (2017)

#203
post #39
post #21

This isn't a great example to me. I doubt the interviewers would disagree that the actual code in MVC runs at the "application tier". I think they were just trying to elicit the idea that the model defines interaction with the database and that the view defines interaction with the browser client. That there is some relation there between MVC and 3-tier architecture. The Wikipedia snippet that disputes any relationsh…

Seconded. What they're calling the right answer is the pedantic answer.

Well, no… the correct answer is that MVC and 3-tier are actually orthogonal concepts. And probably the better answer even in his given interview context.

Re: I had to give a wrong answer to get the job (2017)

#204

Earlier quoted context omitted.

It sounds like you bombed the interview because your answer was not the correct answer for the domain. For games, it absolutely does matter that only some appends trigger latency, because that causes stuttering in the game play. A linked list may be slower in most use cases...but the performance cost is fixed and can be easily designed around.

I feel like I've replied to this same thing about five times now, but, yes, I completely understand the latency concern with growing a dynamic array. At the time, we weren't talking about it. Their question was, "What is the complexity of this?" And I said, "It's constant time over a series of appends." We didn't get past that.

The guy worked at EA for 8 years.. He must know what he is talking about

Re: I had to give a wrong answer to get the job (2017)

#205

I bombed an interview at a game company because I gave a right answer that I couldn't get them to understand. I don't remember the exact problem they wanted me to solve, but the answer involved a dynamic collection and they wanted it to grow with constant time complexity. They were probably looking for a linked list. But I said I'd use a dynamic array because those have constant time when averaged over a series of ap…

There was a meme going around where a doctor took a high school biology quiz.

Q: What are mitochondria?

A: [Long complex scientific answer about ATP synthesis]

Grader: Wrong. Mitochondria are the powerhouse of the cell.

Re: I had to give a wrong answer to get the job (2017)

#206

I was in a job interview several years ago and I was given the following prompt: "You have a database containing locations with their corresponding latitudes and longitudes. We want to be able to input an arbitrary latitude and longitude and have the program return all locations within a radius from that point from the database." My initial reaction was to say "I would use a GIS library/API", but the interviewer want…

Maybe they were expecting converting to 3 dimensional Cartesian coordinates (X/Y/Z), then check that one point is inside the sphere of given radius from the other point?

Re: I had to give a wrong answer to get the job (2017)

#207
post #137
post #129

Earlier quoted context omitted.

Just a thought -- gaming is latency sensitive. Maybe their issue with it wasn't about average performance, but that the once-in-a-while perf hit would be enough to cause a bad experience for the person playing the game? I know I'd be frustrated if there was a predictable lag spike while playing a game.

Any game engine design worth its salt would: 1. Probably not used linked lists (contiguous layout means better cache efficiency) 2. Would try to understand their data requirements and allocate memory up front as much as possible - doing a similar amortized analysis the OP is suggesting rather than a generic "always have O(1) insertion" at the cost of using an inferior data structure (a linked list)

Any game engine architect worth her salt would know to not speak so absolutely about cache coherency, and that if you're dealing with a use-case where iteration is massively infrequent but random insertions and removals are likely, you could be better off with the linked list :)

Re: I had to give a wrong answer to get the job (2017)

#208

I bombed an interview at a game company because I gave a right answer that I couldn't get them to understand. I don't remember the exact problem they wanted me to solve, but the answer involved a dynamic collection and they wanted it to grow with constant time complexity. They were probably looking for a linked list. But I said I'd use a dynamic array because those have constant time when averaged over a series of ap…

Typically interviewers are looking for the general known common way to do things. I heard people failed cause they wrote code that use bitwise AND instead of MODULO to check if a positive integer is even. Just the way it works even if I don't like it.

Re: I had to give a wrong answer to get the job (2017)

#209

Earlier quoted context omitted.

It's not great to have to double your memory usage while you reallocate your array. On more limited devices (see games consoles or mobile devices) you'll end up fragmenting your memory pretty quickly if you do that too often and the next time you try to increase your array you may not have a contiguous enough block to allocate the larger array. There's also the cost of copying objects especially if you don't know if…

> It's not great to have to double your memory usage while you reallocate your array. You don't have to use a growth factor of 2. Any constant multiple of the current size will give you amortized constant complexity. > On more limited devices (see games consoles or mobile devices) you'll end up fragmenting your memory pretty quickly if you do that too often and the next time you try to increase your array you may not…

When you reallocate your array you will in memory have your old array and your new larger array while you move your data over. At the very least you're using 2x and the extra memory for your expansion.

For your other points if you'd mentioned them in the interview you'd probably have been better received. Copying is really only that fast for POD objects (your objects copy constructors may need to do reallocation themselves or worse) so if you're suggesting a general solution you should be aware of that (or at least mention move constructors if they were available at the time) .

I would be surprised if any of the games you worked on actually shipped with an amortised resize of dynamic arrays (at least not for anything that didn't matter in the first place) so I don't know why you'd suggest it as a general solution in a game dev context.

Re: I had to give a wrong answer to get the job (2017)

#210
This is a bad answer even in the contrived context in which it is given.

The better answer is along the lines of: Architecture patterns are abstract concepts whose implementation may vary. You can express an MVC Architecture without a database or without a GUI, however commonly…

Post reply on HN