Odd Even Sort

Sorting Algorithm Odd Even Sort

Odd Even Sort

Given an array of integers, write a function that returns a new array where all the odd numbers are sorted in ascending order and placed at the beginning, followed by all the even numbers sorted in descending order.

For example:

  • Input: [3, 1, 4, 2, 5]
  • Odd numbers (sorted ascending): [1, 3, 5]
  • Even numbers (sorted descending): [4, 2]
  • Output: [1, 3, 5, 4, 2]

Notes

  • The function should not modify the input array but instead return a new sorted array.
  • Aim for clarity and efficiency in your implementation.

Happy coding this January 8th!