题目描述
Given an array arr[] of size N,the task is to arrange the array such that odd elements occupy the odd positions and even elements occupy the even positions. The order of elements must remain the same. Consider zero-based indexing. After printing according to conditions, if remaining, print the remaining elements as it is.
Example 1:
Input: N = 6
arr[] = {1, 2, 3, 4, 5, 6}
Output: 2 1 4 3 6 5
Explanation: Even elements are at
even position and odd elements are
at odd position keeping the order
maintained.
Example 2:
Input: N = 4, arr[] = {3, 2, 4, 1}
Output: 2 3 4 1
Your Task:
This is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function arrangeOddAndEven() that takes array arr[] and size N as parameters and returns an array according to the above-mentioned condition.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).
Constraints:
2 ≤ N ≤ 10^{6}
输入格式
见题面
输出格式
见题面