Challenge: Maximum, Minimum Array

Let’s solve the minimum, maximum array problem.

Problem

Given a sorted array, rearrange it into the maximum-minimum form.

Input

A sorted integer array.

Output

An integer array in a maximum-minimum form.

Sample input

array = { 1, 2, 3, 4, 5, 6, 7 }

Sample output

array = [ 7, 1, 6, 2, 5, 3, 4 ]

Let’s look at the illustration below to better understand the problem.

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