#1502
Can Make Arithmetic Progression From Sequence
newbie · 290 · lc easy +20 · verified · 69.1% accepted · 2,321 likes · top 77%
Description
An arithmetic progression is a sequence where any two consecutive elements differ by the same constant. Given array arr, determine whether its elements can be reordered to form such a sequence. Return true if possible, false otherwise.
Example 1:
Input: arr = [3,5,1]
Output: true
Explanation: We can reorder the elements as [1,3,5] or [5,3,1] with differences 2 and -2 respectively, between each consecutive elements.
Example 2:
Input: arr = [1,2,4]
Output: false
Explanation: There is no way to reorder the elements to obtain an arithmetic progression.
Code
1
2
3