Maximum Difference
Practice
3.8 (541 votes)
Implementation
Sorting
Approved
Easy
Problem
73% Success 5501 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Given N space separated integers. Your task is to arrange them such that the summation M of the absolute differences between every two adjacent numbers is maximum.

Input:

First line of the input contains an integer N.
Second line contains N space separated integers \(A_i\).

Output:

Print the above described M.

Constraints:

  • \(1 \le N \le 1000\).
  • \(1 \le A_i \le 10^{5}\).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
195 votes
Tags:
AlgorithmsEasySearching
Points:20
1 votes
Points:50
Tags:
ApprovedArraysData StructuresHard