#K51762. Difference Between Maximum and Minimum Array Elements
Difference Between Maximum and Minimum Array Elements
Difference Between Maximum and Minimum Array Elements
Given an array of integers, your task is to calculate the difference between the maximum and minimum values in the array. If the array is empty, print 0.
Formally, let \(A = [a_1, a_2, \dots, a_n]\). You need to compute:
\(\text{result} = \begin{cases} \max(A) - \min(A) & \text{if } n>0,\\ 0 & \text{if } n = 0. \end{cases}\)
It is guaranteed that the input format adheres to the specifications below.
inputFormat
The first line of input contains a single integer n
which denotes the number of elements in the array. The second line contains n
space-separated integers representing the elements of the array. If n
is 0, the array is considered empty.
outputFormat
Print a single integer—the difference between the maximum and minimum values of the array. If the array is empty, output 0.
## sample5
3 7 2 5 10
8
</p>