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}\).
Submissions
Please login to view your submissions
Similar Problems
Points:30
3 votes
Tags:
MediumTwo dimensional
Points:30
2 votes
Tags:
Easy-Medium
Points:30
14 votes
Tags:
AlgorithmsApprovedMathMediumOpen
Editorial