LC: 1228. Missing Number In Arithmetic Progression - spiralgo/algorithms GitHub Wiki

1228. Missing Number In Arithmetic Progression:

The Essence:

We should focus on the key here: A value from arr was removed that was not the first or last value in the array.

The question puts an emphasis on this sentence because we need to find the real difference between each element.

difference = number of values / (last value−first value);

Details:

The problem-solver should be familiar with the Binary Search algorithm first.

After calculating the difference, we can easily find the part where the missing element should exist by checking:

if (arr[mid] == arr[0] + mid * difference)