List of Prime Numbers

Recently I had an interview for an internship position with Volocopter. It is an Urban Air Mobility (UAM) company based in Germany. As far as I know, this company is one of the most advance in UAM competition.

One part of the interview was an online coding. The interviewer asked me to “provide a list of all prime number up to 1000”. I found this question interesting as a there’s only one characteristic of a prime number.

A prime number is defined as a number greater than 1 whose factors are 1 and itself.

How do we implement it in a code? I wrote my code on my Github repository.

The idea of the code is pretty simple. First of all, we need to check if a number is a prime number or not. We can implement this by checking the modulo this particular number with a prime number. If the modulo is zero, this particular number is not a prime number.

Since we need to give list of the prime number up to a certain number, we can make a loop to go to reach that upper limit. In this case, we can use for loop. The first for loop will iterate up to the upper limit.

We should calculate the modulo of that particular number with another number. At first, I compared it by using for loop from 1 to that number but this is not efficient. An efficient way is to compare it only with a prime number, as I mentioned earlier. Therefore, we can initiate list of prime number and iterate through this list. If a particular number is a prime number, then add this number to list of prime number.

There you go! List of prime number in an easy way.


Note: During the interview, the interviewer helped me figuring out what I have to do. I didn’t finish the whole code during the interview since it was stopped when the idea was pretty obvious.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s