Favorite Technical Interview Questions?

cguy

Executive Member
Joined
Jan 2, 2013
Messages
9,992
Reaction score
5,051
Seemed like a fun topic. What are your favorite (or most interesting) technical interview questions that you ask, or have been asked during a technical interview? Feel free to answer any posted.

The litmus test question (i.e. a poor answer for this is an early reject for me, but does not indicate sufficiency) that I tend to ask most frequently of developers is:
If you fill a pointer with random data, and write some other random data to the dereferenced address, what is the worst that could happen? Explain.

Another one that had surprising depth, was one that was asked of me:
How would you optimize the following C code for maximum performance:
Given float r=0, and float arrays a[N] and b[N]:
for( uint32_t x=0; x < N; x++)
r += a[x] * b[x];

At each stage of optimization, I was asked the question: What is the limiting factor?
 
Being a good programmer has very little to do with answering 'tricky' questions like these.

Seriously, think about your average working day programming. How often do you ever encounter problems like these? 90% of developing good software is about being able to write readable structured code, the ability to meet deadlines, being able to research effectively, and working well within a team.

By all means ask these questions, but "a poor answer for this is an early reject for me" in my opinion shows you're too focused on the very technical aspects of development and not the person sitting opposite you.
 
Last edited:
One technical gem I got asked at my last interview: "If a group of five customers orders the rib special with coke, calculate your tip".
 
Actually, an understanding of the answer space to these questions is something that I and many other developers absolutely require and use on a daily basis. In terms of personality, they tell me that the candidate has a strong interest in how things actually work.

Regardless, I think you got the wrong end of the stick with my post, I always ask algorithm, math and coding questions too, the exploration of the first one (and the second one to an extent) is just my favorite, not sufficient for a hire, but enough to tell me if the candidate has an interest in how the machine they use works. This is obviously not something I would expect from all programmers, but it is for the ones I personally have needed to hire.
 
I prefer asking questions that highlight a developers understanding of broader OO or implementation problems.

No offence but those kinds of questions are fairly simple because all they require is time with little knowledge or research required.

They are essentially the type of question you would get in a programming competition (ACM/Standard bank IT challenge).

But since we are talking about questions, some of mine:

As a Java dev I like asking experts questions that show their knowledge of the language:
Eg. What is the difference between final keyword on a method variable, field variable, method and class.

It shows that they know the OO principles and that they were able to identify it in Java. You can also see how much research they've done on the language to identify popular pitfalls like final on a class actually being generally bad because it has no performance benefits and final on a method variable being essentially useless to the JVM.

More general questions would be:
What happens when I type in google.com in my browser. Very open ended and tests their knowledge of HTTP and OSI. They decide the depth so good general questions

Also how would you make an application fault tolerant, available and consistent. Shows their knowledge of CAP theorem and shows how they can come up with a good compromising solution that meets most of those requirements. Usually I'll ask this question to see how much knowledge they have of setting up such an environment also.

Does a one way function exists I also like. Can they make the link that a one way function is essentially P=NP problem. Few actually know but some people while explaining it realize it is in fact the case (discounting those that didn't already know).
 
My stab: maybe the question isn't actually this easy, but assuming this question originated in the US (or some other place where 20%), was customary, the expected tip would be exactly the amount of a rib special and a coke (1/5th of order).

EDIT: Just as an FYI, I realize that this was most likely intended as a joke, but I have had similar questions thrown at me out of the blue while interviewing, usually with a view on a) thinking on one's feet, and b) resolving the intuitive response with a particular algorithm. E.g., "estimate the sqrt of 1.71."
 
Last edited:
Gnome, I think you underestimate the level of sophistication a good answer to those questions requires, especially the second one. Still, the key benefit is that qualitative knowledge tends to dictate interest.
 
Gnome, I think you underestimate the level of sophistication a good answer to those questions requires, especially the second one. Still, the key benefit is that qualitative knowledge tends to dictate interest.

I dont know if sophistication is the word I'd use. It just means they need very specific and in depth knowledge of C/C++ and how to get the best of them. Those questions are not relevant anywhere else. And to be fair, they are also less relevant if your constraint is money and time and not algorithm speed. I mean, the second one might shave off a few milliseconds, or seconds perhaps, if N is really large, but what if it takes you a day to optimize that particular piece of code?

I dont really like such specific things. For me, the most important things are a good engineering mindset with regards to maintainability and fault tolerance of code. Algorithm design is something I find personally interesting, but not everyone feels the same.

EDIT: Incidentally, would you mind sharing the answer to the second one? The only obvious thing I can see is that it should be ++x, not x++.
 
I dont know if sophistication is the word I'd use. It just means they need very specific and in depth knowledge of C/C++ and how to get the best of them. Those questions are not relevant anywhere else. And to be fair, they are also less relevant if your constraint is money and time and not algorithm speed. I mean, the second one might shave off a few milliseconds, or seconds perhaps, if N is really large, but what if it takes you a day to optimize that particular piece of code?

I dont really like such specific things. For me, the most important things are a good engineering mindset with regards to maintainability and fault tolerance of code. Algorithm design is something I find personally interesting, but not everyone feels the same.

EDIT: Incidentally, would you mind sharing the answer to the second one? The only obvious thing I can see is that it should be ++x, not x++.

Most compilers would optimise this anyway.
 
Give them a test with some problems basic to quite involved to solve. That'll show you how they think and solve problems.

If they pass that test, come for the "face time" interview.
 
I dont know if sophistication is the word I'd use. It just means they need very specific and in depth knowledge of C/C++ and how to get the best of them. Those questions are not relevant anywhere else. And to be fair, they are also less relevant if your constraint is money and time and not algorithm speed. I mean, the second one might shave off a few milliseconds, or seconds perhaps, if N is really large, but what if it takes you a day to optimize that particular piece of code?

These questions are extremely relevant if code optimization is important to one's business, and actually has very little to do with C/C++ so much as it has to do with understanding how to optimize code for a particular environment (hardware, OS, libraries, etc.), which is a problem that crops up almost everwhere to one degree or another. It may not be the exact problem as above, but you will find that the people who have dealt with optimization a lot, and have a head for that kind of work tend to do well in this question.

Kudos for mentioning that there is a tradeoff between money and time and optimization. Premature optimization is a poor usage of both time and money - a lot of otherwise rational people, just don't get this and spend an uncalled for effort optimizing the wrong code, rather than finding their real hotspots or thinking of a better way to do things.

Another observation about this particular piece of code is that it is a dot product, very often this (or something very similar) is the inner loop of an O(n^2) or ~O(n^3) algorithm (matrix-vec multiplicaiton and matrix-matrix multiplication respectively). This is really important for a lot of statistical analysis, solving systems of linear equations, and for relatively small N, 4x4 matrix operations in computer graphics. Most apps that depend on using linear algebra, will benefit immemsely from a more efficient implementation. A lot of apps are entirely limited by these operations. (FYI, there are libraries that do a lot of this stuff alread (BLAS), however, people who use them extensively often find the need to customize them further, or to optimize for particular special cases that the library does not support), also there are far more cases where heavy floating point arithmetic is used, and a good understanding of techniques like this can offer a huge benefit.

Algorithm design is something I find personally interesting, but not everyone feels the same.

EDIT: Alg. design is just as important to me as a requirement. I want my hires to have both high level software and algorithm design skills, and a good understanding of how the code will actually run in practice.

EDIT: Incidentally, would you mind sharing the answer to the second one? The only obvious thing I can see is that it should be ++x, not x++.

Sure (FYI, I don't expect everyone to get all these points, but I usually expect 1+3 for a good junior hire, 1+2+3 for a good senior hire, and at least 2 out of 3 for 4+5+6 for someone who considers themself a specialist):

1] Some high level optimizations would be that for very large N, you can multi-thread or distribute the computation. There will be a trade-off between computation and transfer time, which will also have to account for the fact that data transfers can be asyncrhonous.

2] WRT to a single thread, the operations performed for each iteration are 1 add, 1 multiply, 2 loads. There is some loop counter+check overhead, but this can be amortized by simple loop unrolling. The limiter at this point is actually the add operation - the reason for this is that the multiplies and loads are indepedent, and assuming the data fits into cache (or the higher level operations (matrix ops) have been blocked to fit into cache, the load+multiply pipelines (separate to each other and add on most contemporary architectures) will be tightly packed, whereas there will be bubbles in the pipeline due to the dependency on the adds ('r' is the only accumulator). Unrolling and adding multiple accumulators (e.g., r0, r1, r2 and r3), will break this dependency long enough to allow the individual adds to complete before their target accumulator is required again. On current AMD/Intel processors this can give you a huge performance boost (~2-3x).

3] If you are using a reasonably new PC (last decade or so), you can use SIMD ops (available as intrinsics) to paralellize the computation at a finer level (possible since the multiplies are all independent, the data is contiguous and the accumulators can be parallelized accordingly), giving you up to an additional 4x boost in performance assuming each execution of size N is not limited by cache throughput or latency. SSE can get you up to 4x perf, and AVX (on Sandy Bridge and above), can get you an extra 8x theoretically (in practice it's more like 6x since the L1 cache can't keep up with the math given a dot product like this, which was written oblivous to the higher level algorithm). PowerPC, CELL and ARM (when configured with NEON) processors all have SIMD units that can give similar benefits. Extra points for mentioning alignment concerns and restrictions.

4] On future Haswell parts, the dual FMA (Fused Multiply Add) pipelines should give you yet another 2x boost (cache allowing).

5] If you can generate and consume this data on a GPU, a GPU can chew through it much faster. If not, the PCIE data transfer costs will kill your benefit. GPUs also benefit from FMA.

6] Extra points for delving into cache details - e.g., the HW prefetecher should hide most latency, but if structured incorrectly in an outer algortihm/loop the dot product operations can be dominated by bandwidth restrictions (mem-to-L3, L3->L2, L2->L1, L1->reg).
 
Last edited:
Interesting thread. Having been working as a "developer" for about 2 years. I'm shocked that I know 20% of what has been mentioned (might have to do with terminology). Any idea where I should start in studying this. Doing my Informatics degree from second semester this year but in the interim. Where do I start?

In the interview's I've been too, we are given a "test" to solve, figure that out and you get called in for a face-time interview. And that was it,
 
My favorite question is always: Why is a manhole round, gimme 3 reasons you can think of
 
Top
Sign up to the MyBroadband newsletter
X