Ctrl K

Reorder Into Even Steps

Easy
You are given an integer array values. Can its elements be rearranged so that the difference between every pair of neighbours is the same? Return True if such an arrangement exists and False otherwise.
Example 1
values=[11, 2, 8, 5] → True

Ordered as [2, 5, 8, 11], every step is 3.

Example 2
values=[1, 4, 6] → False

In any order the gaps differ: 3 and 2.

Example 3
values=[7, 7, 7] → True

A step of 0 counts too.

Constraints
  • 2 ≤ len(values) ≤ 1000
  • -10⁶ ≤ values[i] ≤ 10⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMerge Into the Spare Tail EasyThe Candidate With Most Votes EasyDoes Any Value Repeat EasyMake It to Every Meeting EasyThe Lost Ticket Easy
loading Python…
Input
values=[11, 2, 8, 5]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 159 tests on the server, hidden ones included.