EMC Interview Question Software Engineer in Tests

  • emc-interview-questions
    0
    of 0 votes
    3
    Answers

    Write a function that counts the number of primes in the range [1-N]. Write test cases for this function.

    - panshul21 on June 02, 2012 in India for RSA Report Duplicate | Flag
    EMC Software Engineer in Test

Team: RSA
Country: India
Interview Type: Written Test


Comment hidden because of low score. Click to expand.
1
of 1 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 on 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 on 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 on June 03, 2012 | Flag


Add a Comment
Name:

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

Books

is a comprehensive book walking you through every aspect of getting a job at a top tech company, while focuses on software engineering interviews.

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