Q-40 Can Make Arithmetic Progression From Sequence - LeetCode

PHOTO EMBED

Fri Jan 27 2023 15:47:48 GMT+0000 (Coordinated Universal Time)

Saved by @Ayush_dabas07

class Solution {
    public boolean canMakeArithmeticProgression(int[] arr) {
        Arrays.sort(arr);
        int d = arr[1] - arr[0];
        int a = arr[0];
        
        for(int i =2 ;i < arr.length;i++)
        if(arr[i] != (a + i*d)) return false;

        return true;
    }
}
content_copyCOPY

https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/