• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
July 04, 2022 |4.2K Views

Find the missing element in the Arithmetic Progression

Description
Discussion

A Simple Solution is to linearly traverse the array and find the missing number. Time complexity of this solution is O(n). Below is the implementation
From Mathematical formulae we know that in an AP,
Sum of the n elements = (n/2)(a+l)
n is the number of elements, a is the first element and l is the last element

If we apply this formulae and keep it in a variable s, And take the sum of all elements and keep them in sum. We will get the missing number by s-sum(As sum doesnt includes the missing number)


Find the missing element in the Arithmetic Progression : https://www.geeksforgeeks.org/find-missing-number-arithmetic-progression/