441. Missing Number In Arithmetic Progression

In some array arr, the values were in arithmetic progression: the values arr[i + 1] - arr[i] are all equal for every 0 <= i < arr.length - 1.

A value from arr was removed that was not the first or last value in the array.

Given arr, return the removed value.

Example 1:

Input: arr = [3, 6, 9, 15, 21]

Output: 12

Explanation: The previous array was [3, 6, 9, 12, 15, 18].

Example 2:

Input: arr = [25, 20, 15, 5]

Output: 10

Explanation: The previous array was [25, 20, 15, 10, 5].

Now Your Turn!

Pick the correct output for the given input

Input: arr = [100, 80, 60, 20]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 3 <= arr.length <= 1000
  • 0 <= arr[i] <= 105
  • The given array is guaranteed to be a valid array.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
int missingNumber(vector<int> &arr) {
// Your code goes here
}
};
Test Case

Input:

Arr