Find the Missing Number in an Arithmetic Progression
You are given a sorted array consisting of ‘N’ distinct integers, forming a nearly complete Arithmetic Progression, except for one missing element. Your task is to find the missing number in the sequence.
Input:
The first line of the input contains an integer 'T' denoting the number of test cases.
The first line of each test case contains a single positive integer 'N' denoting the number of elements in the sequence.
The second line of each test case contains 'N' space-separated integers.
Output:
For each test case, output a single integer that represents the missing element in the given sequence.
Print the result for each test case on a new line.
Example:
Input:
T = 1
N = 5
sequence = [1, 3, 7, 9, 11]
Output:
5
Explanation:
The given sequence is missing '5'. The sequence should be [1, 3, 5, 7, 9, 11].
Constraints:
- 1 ≤ T ≤ 50
- 3 ≤ N ≤ 104
- -109 ≤ Arr[i] ≤ 109
Note:
1. An Arithmetic Progression sequence is defined as a sequence [arr0, arr1, ..., arrn-1] where for each 'i' (0 ≤ i < n - 1), arr[i+1] - arr[i] is the same constant.
2. There is exactly one element missing in the sequence.
3. All numbers in the sequence are distinct.
4. The first and last elements in the sequence are guaranteed to be present.
Be the first one to answer
Add answer anonymously...
Top DE Shaw Quality Testing Intern interview questions & answers
Top HR questions asked in DE Shaw Quality Testing Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app