Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5642 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4610 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@sanskar94511 | 603 |

@akashverma4 | 363 |

@swastik8750 | 300 |

@nishunishuraj18 | 286 |

@surajmamgai | 264 |

@anks9013 | 222 |

@nayan2709 | 213 |

@burhanuddinbohra72 | 212 |

@realname | 203 |

@amank8975 | 203 |

@manmeetkaur18102000 | 202 |

Complete Leaderboard |

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.

**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.

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

**Your Task: **

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<=10^{5}

1<=arr[i]<=10^{5}

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?

Yes
Print an array in Pendulum Arrangement

...