Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5642
@Quandray 5233
@akhayrutdinov 5111
@saiujwal13083 4610
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3413
Print an array in Pendulum Arrangement
Basic Accuracy: 67.07% Submissions: 91 Points: 1

Write a program to input a list of n integers in an array and arrange them in a way similar to the to-and-fro movement of a Pendulum.

• The minimum element out of the list of integers, must come in center position of array. If there are even elements, then minimum element should be moved to (n-1)/2 index (considering that indexes start from 0)
• The next number (next to minimum) in the ascending order, goes to the right, the next to next number goes to the left of minimum number and it continues like a Pendulum.

Example 1:
Input :
n = 5
arr[] = {1, 3, 2, 5, 4}
Output :
5   3   1   2   4
Explanation:
The minimum element is 1, so it is
moved to the middle. The next higher
element 2  is moved to the right of
the middle element while the next
higher element 3 is moved to the left
of the middle element and this process
is continued.

Example 2:
Input :
n = 5
arr[] = {11, 12, 31, 14, 5}
Output :
31   12   5   11   14



You don't need to read input or print anything. Your task is to complete the function pendulumArrangement() which takes the array arr[] and its size n as inputs and returns  the vector array in Pendulum Arrangement.

Expected Time Complexity: O(n. Log(n))
Expected Auxiliary Space: O(n)

Constraints:
1<=n<=105
1<=arr[i]<=105