#K48567. Difference Between Largest and Smallest Elements
Difference Between Largest and Smallest Elements
Difference Between Largest and Smallest Elements
You are given an array of integers. Your task is to compute the difference between the maximum and minimum elements of the array. In mathematical terms, given an array arr, you need to find:
\( \text{result} = \max(arr) - \min(arr) \)
If the array is empty, consider the difference as 0.
inputFormat
The input is read from standard input (stdin) and 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 \) integers separated by spaces.
If \( n = 0 \), the array is considered empty.
outputFormat
Output a single integer to standard output (stdout) which is the difference between the maximum and minimum elements of the list.
## sample6
3 1 4 1 5 9
8