I forgot to mention, the worst part about trick questions is that you never quite know what's meant to be a trick question and what's not, and handling that gap can be extremely tricky.
For example:
>> Which C++ data structure would you use to store a sorted list of 5,000 integers, a linked list or a vector? The values will be randomly generated one at a time, and after inserting an integer the list must be in a sorted state.
> I would use a vector because of its compact and linear nature. It would-
>> Sorry, the correct answer is a linked list. With an array if you want to insert something in the middle it's going to require you to move all elements that come afterward. Linked lists on the other hand have a constant time cost for insertion and removal.
> But the cost of constant cache misses while traversing the linked list are going to significantly outweigh the cost of shifting the array by one space. And on top of that the 3-4x overhead is going to push nearby nodes out of the cacheline.
>> I'm not convinced.
> We could benchmark it together, or find an existing benchmark online.
>> We're on a strict schedule here, so let's just move on to the next question.
> No thanks, I've realized I wouldn't be a good fit for this position. Thank you for your time and best of luck.
How do you handle a situation like that, where you're asked a trick question but the interviewer doesn't know the trick? It's difficult to find a balance between assertiveness and argumentation.
Do you insist on giving the correct answer and backing it up with facts? Or do you tend toward conflict avoidance, taking the loss on one question and hoping to make it up on the rest?
When you're on a team, you can plan your approach based on the personalities and culture around you. But in an interview you usually have minutes of experience talking to your interviewer. Would they be impressed at your knowledge, confidence, and assertiveness? Or will they perceive your confidence as egotism, your assertiveness as an issue with authority, and your knowledge as incompetence?
The correct answer varies based on the interviewer's personality and your tactfulness, but realistically you need to either stand your ground or walk away. If you acquiesce, you're setting yourself up for a miserable work environment.
I had a phone interview situation like this the other day. The interviewer asked me what I thought of the C++ 11 "auto" specifier. I told him I preferred explicit types for pragmatic reasons and as an aside mentioned that "auto" keyword used to be used for something else in C++. He told me that wasn't true.
(Hmmm, OK. Let it slide Chris. Not going to score any points by proving him wrong...)
I was interviewing for a software architect position and before my now manager interviewed, i interviewed with some junior developers. I started talking about what I thought about some of the latest features of EcmaScript. One of the developers said "we don't use EcmaScript we use JavaScript".
As far as auto goes, I'm in the camp of using it unless the type makes the code clearer, but I get where you're coming from.
When it comes to iterators and such, that's where I think auto really shines. Those types only exist because they have to and I just don't care about having the noise there.
“It depends on how often the data will change. A linked list will be good for [situation x], but a vector might give better performance in [situation y].”
I’d give more points for that answer because it shows a deep understanding.
The only “correct” answer here is “linked list”. Any other answer is officially “wrong”.
I’ve had interviews like that. If the fundamental basis for the question is wrong, and the person asking the question doesn’t understand the material in front of them, then it doesn’t matter.
What’s annnoying to me is when companies keep contacting me about job openings they have, but where the interview process works like this.
There’s a reason why I don’t work at companies like that, and I no longer respond to invitations from companies like that.
I won’t name any names here, but I don’t think anyone here would be surprised.
This reminds me so much of high school and university physics tests - the hardest part was guessing the level the teacher was thinking at and answering accordingly (or covering all bases with conditionals if possible).
I feel this issue comes up in many more places than just interviews.
My bad, that's a transcription error. The original question was which would you use: a linked list or a vector? I've edited the post to be more clear on that.
For example:
>> Which C++ data structure would you use to store a sorted list of 5,000 integers, a linked list or a vector? The values will be randomly generated one at a time, and after inserting an integer the list must be in a sorted state.
> I would use a vector because of its compact and linear nature. It would-
>> Sorry, the correct answer is a linked list. With an array if you want to insert something in the middle it's going to require you to move all elements that come afterward. Linked lists on the other hand have a constant time cost for insertion and removal.
> But the cost of constant cache misses while traversing the linked list are going to significantly outweigh the cost of shifting the array by one space. And on top of that the 3-4x overhead is going to push nearby nodes out of the cacheline.
>> I'm not convinced.
> We could benchmark it together, or find an existing benchmark online.
>> We're on a strict schedule here, so let's just move on to the next question.
> No thanks, I've realized I wouldn't be a good fit for this position. Thank you for your time and best of luck.
How do you handle a situation like that, where you're asked a trick question but the interviewer doesn't know the trick? It's difficult to find a balance between assertiveness and argumentation.
Do you insist on giving the correct answer and backing it up with facts? Or do you tend toward conflict avoidance, taking the loss on one question and hoping to make it up on the rest?
When you're on a team, you can plan your approach based on the personalities and culture around you. But in an interview you usually have minutes of experience talking to your interviewer. Would they be impressed at your knowledge, confidence, and assertiveness? Or will they perceive your confidence as egotism, your assertiveness as an issue with authority, and your knowledge as incompetence?
The correct answer varies based on the interviewer's personality and your tactfulness, but realistically you need to either stand your ground or walk away. If you acquiesce, you're setting yourself up for a miserable work environment.