Magicsheet logo

Missing Number In Arithmetic Progression

Easy
100%
Updated 6/1/2025

Asked by 1 Company

Topics

Missing Number In Arithmetic Progression

What is this problem about?

The Missing Number In Arithmetic Progression problem gives you an array that should form an arithmetic progression (equal difference between consecutive terms) but has exactly one number missing. Find the missing number. This Missing Number In Arithmetic Progression coding problem tests your ability to identify the common difference and locate the gap using binary search or linear scan.

Why is this asked in interviews?

Audible asks this to test understanding of arithmetic progressions and the ability to derive the common difference from the first and last elements — even when the full sequence is incomplete. The array and math interview pattern is applied cleanly, and the problem rewards precise reasoning about expected vs actual values.

Algorithmic pattern used

Determine common difference + binary search. The expected difference d = (arr[n-1] - arr[0]) / n. Then binary search: at index i, expected value = arr[0] + i * d. Find the first index where arr[i] != arr[0] + i*d. The missing number is arr[i-1] + d.

Example explanation

Array: [2, 4, 8, 10, 12]. Expected difference = (12-2)/5 = 2. Wait, let me check: n=5, last=12, first=2, d=(12-2)/5=2. Check index 2: expected = 2+2*2=6, actual = 8. Mismatch at index 2. Missing = arr[1]+d = 4+2 = 6.

Common mistakes candidates make

  • Computing d as arr[1] - arr[0] (wrong if the missing number is the second element).
  • Not using (arr[n-1] - arr[0]) / n as the safe formula for d.
  • Off-by-one in binary search when locating the gap position.
  • Not handling the edge case where all elements are equal (missing number equals any element).

Interview preparation tip

For arithmetic progression problems, always compute the common difference from the endpoints (last - first) / n rather than adjacent elements — a missing early element corrupts the local difference. This is a fundamental insight for all arithmetic sequence gap problems. After solving this, practice finding multiple missing numbers or verifying whether an array can form an AP with rearrangement.

Similar Questions