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 had to give a wrong answer to get the job (2017)
201–210 of 409 posts
Re: I had to give a wrong answer to get the job (2017)
#202I 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…
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)
#203This 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.
Re: I had to give a wrong answer to get the job (2017)
#204Earlier 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.
Re: I had to give a wrong answer to get the job (2017)
#205I 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…
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)
#206I 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…
Re: I had to give a wrong answer to get the job (2017)
#207Earlier 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)
Re: I had to give a wrong answer to get the job (2017)
#208I 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…
Re: I had to give a wrong answer to get the job (2017)
#209Earlier 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…
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)
#210The 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…