Can Make Arithmetic Progression From Sequence

A sequence of numbers is called an arithmetic progression if the difference between any two consecutive elements is the same. Given an array of numbers `arr`, return `true` if the array can be rearranged to form an arithmetic progression. Otherwise, return `false`.

30:00

Can Make Arithmetic Progression From Sequence
easy
Free written solution
Topics
Companies

A sequence of numbers is called an arithmetic progression if the difference between any two consecutive elements is the same.

Given an array of numbers arr, return true if the array can be rearranged to form an arithmetic progression. Otherwise, return false.

Example 1:
Input: {"arr":[3,5,1]}
Output: true
Constraints:
  • 2≤arr.length≤10002 \leq \text{arr.length} \leq 1000

  • −106≤arr[i]≤106-10^6 \leq \text{arr}[i] \leq 10^6

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"arr":[3,5,1]}

Sorted or not, a progression is pinned down by its two ends, so first find the smallest and largest of the 3 values.

arr (unsorted)

3
5
1
Variables
VariableValue
n3
DepthFunction Call
Stack empty
0/8