Can Make Arithmetic Progression From Sequence

EasyArrays & Hashinghashing

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A sequence is an **arithmetic progression** when the difference between every pair of consecutive elements is the same. Given an integer array arr, return true if its elements can be reordered to form an arithmetic progression, and false otherwise. Aim for O(n) time if you can (sorting in O(n log n) is also accepted).

Examples

Input: arr = [5,1,3]
Output: true
Reordered as [1,3,5] (or [5,3,1]) every step is 2.
Input: arr = [1,2,4]
Output: false
No ordering of these values has equal gaps.

Constraints

  • 2 <= arr.length <= 1000
  • -10^6 <= arr[i] <= 10^6

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More hashing problems