Find the missing number in Arithmetic Progression - GeeksforGeeks
Find the missing number in Arithmetic Progression Given an array that represents elements of arithmetic progression in order. One element is missing in the progression, find the missing number. Examples: Input: arr[] = {2, 4, 8, 10, 12, 14} Output: 6 Input: arr[] = {1, 6, 11, 16, 21, 31}; Output: 26 We strongly recommend to minimize your browser and try this yourself first. A Simple Solution is to linearly traverse the array and find the missing number. Time complexity of this solution is O(n). We can solve this problem in O(Logn) time using Binary Search . The idea is to go to the middle element. Check if the difference between middle and next to middle is equal to diff or not, if not then the missing element lies between mid and mid+1. If the middle element is equal to n/2th term in Arithmetic Series (Let n be the number of elements in input array), then missing element lies in right half. Else element lies in left half. Following is C implementation of above idea.Read full article from Find the missing number in Arithmetic Progression - GeeksforGeeks