Interview Questions

164. rearrange an array of integers such that on one side .......

Microsoft Interview Questions and Answers


(Continued from previous question...)

164. rearrange an array of integers such that on one side .......

Question:
rearrange an array of integers such that on one side you have all even numbers and the other side you have all odd numbers.
now among the even numbers, they should be sorted and among the odd numbers they should be sorted


maybe an answer:


bool mycompare(int a, int b)
{
if((a%2 == 0 && b%2==0) || (a%2==1 && b%2==1))
return a < b;


if(a%2 ==0)
return true;

return false;
}

rearrange(int A[], int n);
{
sort(A,A+n,mycompare);
}

complexity is O(nlogn)

(Continued on next question...)

Other Interview Questions