Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given an array **arr[] **of size **N** containing equal number of odd and even numbers. Arrange the numbers in such a way that all the even numbers get the even index and odd numbers get the odd index.

**Note: **There are multiple possible solutions, Print any one of them. Also, 0-based indexing is considered.

**Example 1:**

Input:N = 6 arr[] = {3, 6, 12, 1, 5, 8}Output:1Explanation:6 3 12 1 8 5 is a possible solution. The output will always be 1 if your rearrangement is correct.

**Input:
**N = 4
arr[] = {1, 2, 3, 4}
**Output :**
1

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **reArrange()** which takes an integer N and an array arr of size N as input and reArranges the array in Place without any extra space.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 ≤ N ≤ 10^{5}

1 ≤ arr[i] ≤ 10^{5}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

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

YesLoading...

Even and Odd

...