Can Make Arithmetic Progression

Easy

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:true
Explanation:

Rearrange to [1,3,5].

Input:arr = [1,2,4]
Output:false
Explanation:

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:true
Explanation:

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

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!