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


Interview Answer

2 Answers


List sieveOfEratosthenes(int max){
List primes = new ArrayList();
boolean[] flags = new boolean[max+1];
int prime = 2;
   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;

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

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


Anonymous on Jul 15, 2019

Add Answers or Comments

To comment on this, Sign In or Sign Up.