#K92627. Maximum Beauty of Array
Maximum Beauty of Array
Maximum Beauty of Array
Given an array of integers, you are allowed to remove at most one element from the array. The beauty of an array is defined as the difference between its maximum and minimum elements, i.e., (\text{beauty} = \max(arr) - \min(arr)). Your task is to determine the maximum beauty achievable by optionally removing one element from the array. Note that if the array contains only one element, its beauty is defined to be 0.
In other words, if you have an array (a_1, a_2, \dots, a_n), you may remove one element at most, and you need to calculate the maximum possible value of (\max(arr') - \min(arr')) where (arr') is the array after the removal (or even if you choose not to remove any element).
inputFormat
The input consists of two lines. The first line contains a single integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers, representing the elements of the array.
outputFormat
Output a single integer, which is the maximum beauty of the array after removing at most one element.## sample
5
1 5 3 1 2
4