This page is still under construction.

Parts of this page are still being built. What you see may change.

Maximize Differences

Interview

Time limit1sMemory limit256 MB

Summary
Reorder the given array so the sum of absolute differences between neighbors is as large as possible.
Level

Medium5 of 10

Topics
Greedy, Sorting, Array
Solved
No attempts yet

Problem

Reorder the array to maximize the sum of adjacent absolute differences.

Input

N and array A.

Output

Print the maximum value.

Examples1

  1. Example 1

    Input
    6
    20 1 15 8 4 10
    
    Expected output
    62