Clean Power Research Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

In case that array 2 is long enough to accommodate both of the arrays then its is filled its size minus array 1's size. (len2-len1 = biggest number on array 2)

int* mergeSort(int* arr1, int len1, int* arr2, int len2)
{
	int* runner = arr2 + len2 -1; //will mark the cell we want to place the bigger number
	int realLen2 = len2 - len1; //the actual length of array2- the values for the merge
	
	int* endOfArr1 = arr1 + len1 -1; //the end of array1 which is the biggest number.
	int* endOfArr2 = arr2 + realLen2 -1; //the biggest number on array2
	
	//run until you reach the end of one of the arrays
	//it will always be completely sorted by then.
	while(len1 > 0 && realLen2 > 0)
	{
		if(*endOfArr1 >= *endOfArr2)
		{
			*runner = *endOfArr1;
			endOfArr1--;
			len1--;
		}
		else
		{
			*runner = *endOfArr2;
			endOfArr2--;
			realLen2--;
		}
		runner--;
	}
	
	//in case there are leftovers in array1 merge them (in case all array1 is smaller)
	while(len1 > 0)
	{
		*runner = *endOfArr1;
		endOfArr1--;
		len1--;
		runner--;
	}
	return arr2;
}

- eladyanai22 January 24, 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