Interview Questions

246. An array is given like {1,4,5,2,3,6,7}

Microsoft Interview Questions and Answers


(Continued from previous question...)

246. An array is given like {1,4,5,2,3,6,7}

Question:
An array is given like {1,4,5,2,3,6,7}. sort the odd elements in descending order and even numbers in ascending order. so result would be {7,5,3,1,2,4,6}


maybe an answer:


2-step way:
1) set i = 0; and j = n - 1; swap the positions of odd numbers and even ones. O(n)
2) sort the even and odd numbers separately using qsort. Worst case is O(nlogn).
so O(nlogn) time and O(1) space.

(Continued on next question...)

Other Interview Questions