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.

- kr.neerav August 06, 2014 | Flag Reply
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.

- S August 07, 2014 | Flag Reply
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.

- S August 07, 2014 | Flag Reply
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;
	}
}

- TheShocker1999 November 30, 2015 | Flag Reply
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....

- vrajendra.singh.mandloi March 23, 2015 | 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