Can All Values Be Rearranged into an Arithmetic Progression?

Quick Overview

Can All Values Be Rearranged into an Arithmetic Progression?. Determine whether every entry of arr can be reordered so that consecutive differences are all equal.

Can All Values Be Rearranged into an Arithmetic Progression?

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Determine whether every entry of arr can be reordered so that consecutive differences are all equal. Return true or false; no particular rearrangement is requested. ```cpp class Solution { public: bool canMakeArithmeticProgression(vector<int>& arr); }; ``` ### Examples **Example 1:** ```text Input: arr = [4,-2,1] Output: true Explanation: Sorting gives[-2,1,4],whose consecutive differences are both3. ``` **Example 2:** ```text Input: arr = [2,2,5] Output: false Explanation: Sorted consecutive differences are0 and3,and no arithmetic progression uses exactly these values. ``` ### Constraints - arr has length 2 to 1000. - Each value lies in `[-1000000,1000000]`. ### Contract considerations The boolean result is deterministic even if multiple arrangements would work. ```hint Read the boundary condition All supplied occurrences must appear in the rearrangement. Include duplicate values, negative values, and arrays of length two. ``` ### Boundary reminders The boolean result is deterministic even if multiple arrangements would work.

Overview: Can All Values Be Rearranged into an Arithmetic Progression?. Determine whether every entry of arr can be reordered so that consecutive differences are all equal.

Google logo
Google
Aug 17, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Determine whether every entry of arr can be reordered so that consecutive differences are all equal. Return true or false; no particular rearrangement is requested.

class Solution {
public:
    bool canMakeArithmeticProgression(vector<int>& arr);
};

Examples

Example 1:

Input: arr = [4,-2,1]
Output: true
Explanation: Sorting gives[-2,1,4],whose consecutive differences are both3.

Example 2:

Input: arr = [2,2,5]
Output: false
Explanation: Sorted consecutive differences are0 and3,and no arithmetic progression uses exactly these values.

Constraints

  • arr has length 2 to 1000.
  • Each value lies in [-1000000,1000000] .

Contract considerations

The boolean result is deterministic even if multiple arrangements would work.

Boundary reminders

The boolean result is deterministic even if multiple arrangements would work.