Microsoft Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

I think, the question was about to find a sorting method which can sort items having non-trivial comparison method. Thats why question says that "tems can be compared with each others." Hence any sorting technique can be used with the tweak that now instead of assuming the trivial comparison (by way of > , < ), the sorting method must take a function (or function pointer) which does the comparison on the items being sorted.

- Pavi April 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Any comparison sort will do. Heap or quick sort will be good.

- alex March 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

question seems to be wrong .........
otherwise bubble sort will be suitable for ur queiry........

- hckr March 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

One should prefer stable sort in such questions, i think.

- Anonymous March 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

is it asking to implement the compare function used in qsort()?

- ycai April 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The question is more open ended, you can use any kind of sorting method on it but the best complexity with true in place sort will be done using Quick sort with complexity of O(nlogn).

- Anonymous April 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main()
{
int array[100], n, c, d, swap;

printf("Enter number of elements\n");
scanf("%d", &n);

printf("Enter %d integers\n", n);

for (c = 0; c < n; c++)
scanf("%d", &array[c]);

for (c = 0 ; c < ( n - 1 ); c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (array[d] > array[d+1]) /* For decreasing order use < */
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}

printf("Sorted list in ascending order:\n");

for ( c = 0 ; c < n ; c++ )
printf("%d\n", array[c]);

return 0;
}

- shweta June 09, 2013 | 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