EMC Interview Question for Software Engineer in Tests


Team: RSA
Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
2
of 2 vote

static int getNumberOfPrime(int N) {
    int count = 0;
    for (int i=2; i<=N; i++) {
        int max = (int)Math.sqrt(i);
        boolean prime = true;
        for (int j=2; j<=max; j++) {
            if (i%j == 0 && i != j) {
                prime = false;
                break;
            }
        }
        if (prime) {
            count++;
            System.out.print(i + ",");
        }
    }
    return count;
}

- sqw June 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int fun(int N)
{
int array[N] ={0};
int i= 2,j;
while(i<sqrt(N))
{
j =i;
j=j+j;
while(j<N)
{
array[j] = -1;
j = j+i;
}
i++;
}
j=0;
for(i=0;i<N;i++)
if(array[i]==-1)
j++;
return(j);
}

- Raunak June 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you please explain why you need array? The way I see it solved is loop till SQRT(N) if loop counter is prime increment j and return j.

- Anon June 03, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool isPrime(int n) {
  if(n == 2 || n == 3)
    return true;

  for(int i = 2; i <= n/2; i++) {
    if(n%i == 0) {
      return false;
    }
  }
  return true;
}

int getNumberofPrime(int n) {
  int count = 0;
  for (int i=2; i <= n; i++) {
    if(isPrime(i))
      count++;
    }
  return count;
}

- Vickey May 04, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More