## SumoLogic Interview Question for Software Engineer in Tests

Country: India
Interview Type: Phone Interview

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

Do you mean to find out if a number is prime or the next prime number? Also i guess you mean O(n) complexity.

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

O(sqrt n). We can also do this in O(1) if we are allowed to use O(n) memory space. It's a tradeoff.

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

O(sqrt n). We can also do this in O(1) if we are allowed to use O(n) memory space. It's a tradeoff.

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

better solution for range of primes O(N2) complexity:

``````int main() {
int max = 100;
int min = 0;
int sq = 0;

for (sq = 1; sq*sq<max; sq++){}

if (min <= 2)
for (int i = 1; i <= 2; i++){ cout << i << endl;}

min += ((min % 2 == 0) || (min == 0));

for (int i = min; i < max; i+=2)
{
bool prmFlag = true;
for (int j = sq; j > min - 1; j--)
{
if (j % 2 != 0)
if ((i % j == 0) && (j > 2) && (j != i))
prmFlag = false;
}
if ((prmFlag == true) && (i > 2))
cout << i << endl;
}
}``````

Comment hidden because of low score. Click to expand.
-1
of 1 vote

One Good way to Find out Prime Number is

``````public static void primeNumbers(int n) {
boolean flag = true;
if(n%2 == 0) {
flag = false;
} else {
for(int i=n/2+1;i>1;i-=2){
if(n%i == 0) {
flag = false;
}
}
}
System.out.println("\n"+n+" is a Prime Number.. "+flag);
}``````

Please do let me know if someone has a better solution than this .. even recursion is great....

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.

### 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.