Be the first user to complete this post
|
Add to List |
56. Sort an Array - odd numbers appear first in ascending order followed by the even numbers in descending order.
Objective: Given an array of intergers, sort it such that the odd numbers appear first followed by the even numbers . The odd numbers in ascending order and the even numbers in descending order.
Example:
Input Array : 1 2 3 4 5 6 7 8 9 10 Output : 1 3 5 7 9 10 8 6 4 2
Approach:
- First separate the odd numbers and even numbers, put odd numbers first followed by even numbers using quick sort technique. (Click here to read about quick sort)
- Now sort the odd numbers in ascending order
- Sort the even numbers in descending order.
Original Array : 1 2 3 4 5 6 7 8 9 10 Output Array : 1 3 5 7 9 10 8 6 4 2