You are given an array arr: the remaining terms, in their original order, of an integer arithmetic progression (a sequence with a constant difference between consecutive terms) after exactly one interior term was removed (never the first or last term).
Return the removed term.
The common difference may be negative or zero; when it is zero, every term is equal and the removed term equals them.
Examples
Example 1
Input: arr = [3,7,11,19]
Output: 15
Explanation: The original progression was 3, 7, 11, 15, 19 with difference 4.
Example 2
Input: arr = [10,7,1]
Output: 4
Explanation: The original progression was 10, 7, 4, 1 with difference -3.
Example 3
Input: arr = [5,5,5]
Output: 5
Explanation: A constant progression, so the removed term equals every other term.
Constraints
3≤arr.length≤105
−109≤arr[i]≤109
arr was produced by deleting exactly one interior term from a valid integer arithmetic progression.
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up