#### Loading...

Segregate Even and Odd numbers
Basic Accuracy: 44.57% Submissions: 3886 Points: 1

Given an array Arr[], write a program that segregates even and odd numbers. The program should put all even numbers first in sorted order, and then odd numbers in sorted order.

Example 1:

Input:
N = 7
Arr[] = {12, 34, 45, 9, 8, 90, 3}
Output: 8 12 34 90 3 9 45
Explanation: Even numbers are 12, 34,
8 and 90. Rest are odd numbers. After
sorting even numbers 8 12 34 90 and
after sorting odd numbers 3 9 45. Then
concat both.


Example 2:

Input:
N = 5
Arr[] = {0, 1, 2, 3, 4}
Output: 0 2 4 1 3
Explanation: 0 2 4 are even and 1 3
are odd numbers.

Your Task:
You don't need to read input or print anything. Your task is to complete the function segregateEvenOdd() which takes the array of integers arr[] and as parameters and returns void. You need to modify the array itself.

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)

Constraints:
1 ≤ N ≤ 105
0 ≤ Arr[i] <=105

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

#### My Submissions:

Login to access your submissions.

Segregate Even and Odd numbers