Showing:
Handle Score
@Ibrahim Nash 6564
@mb1973 5785
@Quandray 5275
@akhayrutdinov 5111
@saiujwal13083 5074
@kirtidee18 4639
@sanjay05 3762
@mantu_singh 3712
@gfgaccount 3627
@marius_valentin_dragoi 3525
Rearrange array such that even positioned are greater than odd
Easy Accuracy: 38.03% Submissions: 856 Points: 2

Given an array A of n elements, rearrange the array according to the following relations :
, if i is even.
, if i is odd.[Considering 1-indexed array]
Return the resultant array.

Example:

Input 1:
A[] = {1, 2, 2, 1}
Output:
1 2 1 2
Explanation:
Both 2 are at even positions and 1 at odd satisfying
given condition

Input 2:
A[] = {1, 3, 2}
Output:
1 3 2
Explanation:
Here, the array is already sorted as per the conditions.

This is a function problem. The input is already taken care of by the driver code. You only need to complete the function assign() that takes an array (arr), sizeOfArray (n), and return the resultant array. The driver code takes care of the printing.

Expected Time Complexity: O(NLOG(N)).
Expected Auxiliary Space: O(1).

Constraints:

1 ≤ N ≤ 105
1 ≤ arr[i] ≤ 106