1228. Missing Number In Arithmetic Progression
Problem
Find the missing number in an arithmetic progression array.
Given a sorted array arr that represents an arithmetic progression with a constant difference, where exactly one element is missing, find the missing element.
The array should have elements in arithmetic progression, but one is missing. Return the missing element.
Examples
Input: [5,7,11,13]
Output: 9
Input: [15,13,12]
Output: 14
Hints
Calculate the expected common difference as (arr[last] - arr[0]) / (n) where n = arr.length.
Use binary search to find where arr[i+1] - arr[i] != expected diff.
Return arr[i] + diff where the gap is found.
Related Problems
1228. Missing Number In Arithmetic Progression
Find the missing number in an arithmetic progression array.