#K34492. Can Form Arithmetic Sequence
Can Form Arithmetic Sequence
Can Form Arithmetic Sequence
Given a list of n integers, determine whether the array can be rearranged to form an arithmetic sequence. An arithmetic sequence is a sequence of numbers such that the difference between consecutive terms is constant. In other words, after sorting the array, the difference $$d = arr[i] - arr[i-1]$$ should be the same for all valid indices.
The input is provided from standard input. The first number is an integer n representing the number of elements. The next line contains n space-separated integers. Your program should output True
if the integers can form an arithmetic sequence, and False
otherwise.
inputFormat
The first line of input contains a single integer n (the number of elements). The second line contains n space-separated integers which form the array.
outputFormat
Output a single line: either True
if the array can be rearranged to form an arithmetic sequence, or False
otherwise.
3
3 5 1
True