Internship interview questions shared by candidates
How work you work out all the prime numbers up to a given range?
Store all the prime numbers in an array and compare the next number with the array to find out whether it is prime or not.
Sieve of Eratosthenes algorithm. create an array of the numbers, set them all to the value 1. Start at 2, set every second number after 2 to 0. move to the next number (3). change every third number after three to zero. stop when there's no more numbers set to 1 or you reach the end of the array. At the end, the numbers marked 1 are the primes.
Interview candidate - did you give that answer in the interview? If so, what did they say?