Microsoft Interview Question for Software Engineer / Developers






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

This can be done in O(n) time using the merge procedure of MergeSort (Introduction to Algorithms)

- axmt December 30, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void merge(int * a, int na, int *b, int nb, int *c)
{
	int i, aindex = 0, bindex = 0;
	for(i = 0; i<na+nb;i++)
	{
		if(aindex<na && bindex < nb)
		{
			if(a[aindex] < b[bindex])
				c[i] = a[aindex++];
			else
				c[i] = b[bindex++];
		}
		else
			break;
	}
	if(aindex == na)
		for(int j = i; j<na+nb;j++)
			c[j] = b[bindex++];
	else
		for(int j = i; j<na+nb;j++)
			c[j] = a[aindex++];
}

- gauravk.18 March 13, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In Java (there is no need for an additional array):

public static void main(String[] args) {
		int A[] = { 1, 3, 5, 6, 9 };
	    int B[] = new int[12];
	    B[0] = 3;
	    B[1] = 6;
	    B[2] = 8;
	    B[3] = 10;
	    B[4] = 11;
	    B[5] = 13;
	    B[6] = 15;
	    mergeInB(A, B, 7);
	    for (int n : B)
			System.out.print(n + " ");
	}

	

    /**
     * @param a
     * @param b - it will be modified
     * @param j = length of b
     */
    public static void mergeInB(int[] a, int[] b, int j) {
    	int i = a.length - 1, k;
    	j --;
	    for (k = b.length-1; k >= 0; k--) {
	    	 if (i >= 0 && j >= 0) {
		         if (a[i] > b[j]) {
		             b[k] = a[i];
		             i --;
		         }
		         else 
	        	  {
		             b[k] = b[j];
		             j --;
	        	 }		         
	         }
	    	 else break;
	    }
	    	     
	    while(i>=0 && k >=0) {
	         b[k] = a[i];
	         k --;
	         i --;
	    }
	
	    while(j>= 0 && k >=0) {
	         b[k] = b[j];
	         j--;
	         k--;
	     }
    }

- merlinparrajimenez January 15, 2014 | 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