Challenge: Rearrange Sorted Array in Max/Min Form

Given an array, can you re-arrange the elements such that the first position will have the largest number, the second will have the smallest, the third will have the second-largest, and so on. Implement your solution in Java and see if your code runs successfully!

Problem Statement #

In this problem, you have to implement the void maxMin(int[] arr) method. This will re-arrange the elements of a sorted array in such a way that the first position will have the largest number, the second will have the smallest, the third will have the second-largest, and so on.

Note: The given array is sorted in ascending order.

Note: The range of integers in the array can be from 0 to 10000.

Method Prototype #

void maxMin(int[] arr)

Output #

An array in which elements are stored in a max/min form.

Sample Input #

arr = {1, 2, 3, 4, 5}

Sample Output #

arr = {5, 1, 4, 2, 3}

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.