#K91827. Can Form Arithmetic Progression
Can Form Arithmetic Progression
Can Form Arithmetic Progression
Given an array of integers, determine whether the elements can be rearranged to form an arithmetic progression. In an arithmetic progression, the difference between consecutive elements is a constant. Formally, if after sorting the array we have a sequence \(a_0, a_1, \dots, a_{n-1}\), then it must satisfy \(a_i - a_{i-1} = d\) for all \(1 \le i < n\), where \(d\) is a constant.
Your task is to check whether such a rearrangement is possible.
inputFormat
The first line of input contains an integer \(n\) representing the number of elements. The second line contains \(n\) space-separated integers representing the array.
outputFormat
Output a single line with True
if the array elements can be rearranged to form an arithmetic progression; otherwise, output False
.
3
3 5 1
True