#1502
Easy Algorithms Can make arithmetic progression from sequence
Array Sorting
69.1% acceptance
Feb 25, 2026
2315
120
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.
Solution
Rust
Time O(n log n)
Space O(1)
impl Solution {
pub fn can_make_arithmetic_progression(mut arr: Vec<i32>) -> bool {
arr.sort();
let diff = arr[1] - arr[0];
arr.windows(2).all(|w| w[1] - w[0] == diff)
}
}