Description
An arithmetic progression is a sequence where the difference between consecutive elements is constant. Given array arr, return true if it can be rearranged into an arithmetic progression.
Examples
Input:
arr = [3,5,1]Output:
trueExplanation:
Rearrange to [1,3,5].
Input:
arr = [1,2,4]Output:
falseExplanation:
Sorted: [1,2,4]. Differences: 2-1=1 and 4-2=2. Not a constant difference, so not an arithmetic progression.
Input:
arr = [10,10,10,10]Output:
trueExplanation:
All elements are equal, so the common difference is 0. This forms a valid arithmetic progression: [10,10,10,10] with difference 0.
Constraints
- •
2 ≤ arr.length ≤ 1000