Interview Question for Software Engineer in Tests






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

I think;
Recursive -> O(2^n)
Non-Recursive (Dynamic programming) -> O(n^2)

- Anonymous November 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It looks line

O(n^4)

to me for non recursive solution.

- Anonymous November 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Dynamic programming just gives a yes and no answer....how do you get it in O(n2) by DP?

- Anonymous November 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about this: non-recursive O(n^2)

int FindSumCount(int arr[], int n)
{
	int sum=0;
	int count=0;

	for(int i=0;i<n;i++)
	{
		sum=0;
		for(int j=i;j<n;j++)
		{
			sum += arr[j];

			if(sum == 15)
				count++;
			else if(sum<15)
				continue;
			sum -= arr[j];
		}
	}
	return count;
}

- Venkata January 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

for [5, 5, 10, 2, 3] your function returns 3 not 4

- Anonymous January 29, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

// Here is recursive one


static int total=0;
void FindSumCombo(int *, int, int, int);
const int ALLSUM=15;
int _tmain(int argc, _TCHAR* argv[])
{
	
	int* arr = new int[argc-1];
	for(int i=1;i<argc;i++)
	{
		arr[i-1]=_ttoi(argv[i]);
	}

	for(int i=0;i<5;i++)
		FindSumCombo(arr,0,i,4);
	std::cout<<total;
	return 0;
}

void FindSumCombo(int* arr, int sum, int start, int end)
{
	if(start==end)
	{
		if(arr[start]+sum==ALLSUM)
		{
			total++;
			return;
		}
		else
		{
			return;
		}
	}
	if(arr[start]+sum==ALLSUM)
	{
		total++;
		FindSumCombo(arr,sum,1+start,end);
	}
	if(arr[start]+sum>ALLSUM)
	{
		FindSumCombo(arr,sum,1+start,end);
	}
	if(arr[start]+sum<ALLSUM)
	{
		FindSumCombo(arr,sum+arr[start],start+1,end);
	}
	return;

	
}

- Anonymous May 01, 2010 | 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