Skip to main content
Post Made Community Wiki
added 34 characters in body
Source Link

My favourite was one a friend of mine used.

Write me a function to generate/print/store the first "n" prime numbers and then explain how it works and how efficient it is.

It works well because:

  1. It's an algorithmic question so it requires the interviewee to be able to think and then explain their thinking - so you can see how their brain works.

  2. It's language independent.

  3. Hardly anyone gets it completely right (there's usual an edge case they miss (1 or 2 normally), or they don't handle negative numbers, so you get to see how they handle bugs and being told that they're wrong.

  4. Most do it as a simple but very slow sieve (e.g. 80% of people will check of n is a prime by dividing n by all integers less than n), which gives you lots of scope for conversations about how they could improve the algorithm based on space/time trade offs e.g. "why are you dividing a number by 4 if you already know it's not divisible by 2?" or "You've worked out that you only need to divide by all prime numbers less than sqrt(n), but that requires you to store those numbers somewhere, so what are the implications of that?")

There's no need for them to get the answer right. If someone can think and explain their thinking then they're a long way down the road for being a good candidate.

My favourite was one a friend of mine used.

Write me a function to generate/print/store the first "n" prime numbers and then explain how it works and how efficient it is.

It works well because:

  1. It's an algorithmic question so it requires the interviewee to be able to think and then explain their thinking - so you can see how their brain works.

  2. Hardly anyone gets it completely right (there's usual an edge case they miss (1 or 2 normally), or they don't handle negative numbers, so you get to see how they handle bugs and being told that they're wrong.

  3. Most do it as a simple but very slow sieve (e.g. 80% of people will check of n is a prime by dividing n by all integers less than n), which gives you lots of scope for conversations about how they could improve the algorithm based on space/time trade offs e.g. "why are you dividing a number by 4 if you already know it's not divisible by 2?" or "You've worked out that you only need to divide by all prime numbers less than sqrt(n), but that requires you to store those numbers somewhere, so what are the implications of that?")

There's no need for them to get the answer right. If someone can think and explain their thinking then they're a long way down the road for being a good candidate.

My favourite was one a friend of mine used.

Write me a function to generate/print/store the first "n" prime numbers and then explain how it works and how efficient it is.

It works well because:

  1. It's an algorithmic question so it requires the interviewee to be able to think and then explain their thinking - so you can see how their brain works.

  2. It's language independent.

  3. Hardly anyone gets it completely right (there's usual an edge case they miss (1 or 2 normally), or they don't handle negative numbers, so you get to see how they handle bugs and being told that they're wrong.

  4. Most do it as a simple but very slow sieve (e.g. 80% of people will check of n is a prime by dividing n by all integers less than n), which gives you lots of scope for conversations about how they could improve the algorithm based on space/time trade offs e.g. "why are you dividing a number by 4 if you already know it's not divisible by 2?" or "You've worked out that you only need to divide by all prime numbers less than sqrt(n), but that requires you to store those numbers somewhere, so what are the implications of that?")

There's no need for them to get the answer right. If someone can think and explain their thinking then they're a long way down the road for being a good candidate.

Source Link

My favourite was one a friend of mine used.

Write me a function to generate/print/store the first "n" prime numbers and then explain how it works and how efficient it is.

It works well because:

  1. It's an algorithmic question so it requires the interviewee to be able to think and then explain their thinking - so you can see how their brain works.

  2. Hardly anyone gets it completely right (there's usual an edge case they miss (1 or 2 normally), or they don't handle negative numbers, so you get to see how they handle bugs and being told that they're wrong.

  3. Most do it as a simple but very slow sieve (e.g. 80% of people will check of n is a prime by dividing n by all integers less than n), which gives you lots of scope for conversations about how they could improve the algorithm based on space/time trade offs e.g. "why are you dividing a number by 4 if you already know it's not divisible by 2?" or "You've worked out that you only need to divide by all prime numbers less than sqrt(n), but that requires you to store those numbers somewhere, so what are the implications of that?")

There's no need for them to get the answer right. If someone can think and explain their thinking then they're a long way down the road for being a good candidate.