Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@shashi1iitk | 398 |

@Suniti Jain | 114 |

@ankish2000nayak | 104 |

@gopalsethlnct | 94 |

@esmadhan | 90 |

@senthil1185 | 90 |

@gyanadipta07 | 89 |

@satwikdash2000 | 85 |

@varunmishra3040 | 83 |

@gamec1634 | 82 |

@pj_1721 | 80 |

Complete Leaderboard |

Given an array **arr[]** of **N** elements in the following format {a1, a2, a3, a4, ….., an/2, b1, b2, b3, b4, …., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, ……, an/2, bn/2} without using extra space.

**Example 1:**

**Input: **N = 4, arr[] = {1, 2, 9, 15}
**Output:** 1 9 2 15
**Explanation**: a1=1 , a2=2 , b1=9 , b2=9
So the final array will be :
a1, b1, a2, b2 = { 1, 9, 2, 15 }
**Example 2:**
**Input: **N = 6
arr[] = {1, 2, 3, 4, 5, 6}
**Output:** 1 4 2 5 3 6

**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 **shuffleArray**() that takes array** arr[], **and an integer** N** as parameters and modifies the given array according to the above-given pattern.

**Expected Time Complexity:** O(NlogN).

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

**Constraints:**

1 ≤ N ≤ 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
Shuffle integers

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.