Pocket Gems Interview Question: Write a program to find all p... | Glassdoor

Interview Question

Software Engineer Interview San Francisco, CA

Write a program to find all prime numbers up to a given

  number.
Answer

Interview Answer

2 Answers

0

List sieveOfEratosthenes(int max){
List primes = new ArrayList();
boolean[] flags = new boolean[max+1];
int prime = 2;
while(primemax)
     break;
   primes.add(prime);
}
   return primes;
}

public void crossOf(int prime, boolean[] flags){
     for(int toCross = prime*prime; toCross < flags.length; toCross+=prime){
          flags[toCross] = false;
     }
 int getNextPrime(boolean[] flags, int prime ){
    prime += 1;
    while(prime

O(n) Solution via The Sieve of Eratosthenes on Jan 1, 2015
0

Someone from Pocket Gems gave me information about what to expect in the job interview at Rooftop Slushie.

https://wwww.rooftopslushie.com

Anonymous on Jul 15, 2019

Add Answers or Comments

To comment on this, Sign In or Sign Up.