Next in Series
Submissions: 4745   Accuracy:

21.12%

  Difficulty: Easy   Marks: 2

Given an array of integers, the task is to check whether it's an arithmetic progression, geometric progression or fibonacci series, and need to print the next number in the series or -99999 if the given numbers does not follow any of the above series. The fibonacci series need not start with 0.   A valid fibonacci series could be 8,9,17

NOTE: In case of clash, following precedence shold be followed: AP>GP>FIBO

Input:
The First line of the input contains a single interger T denoting the number of testcases. Then T test cases follow. Each test cases consists of two lines. First tline of each test case contains an interger N denoting the no. of integers in an array. The second line of each test case contains N integers denoting the array elements.

Output:
Corresponding to each test case, print the desired output modulo 10^9+7 in a new line.

NOTE: In case of floating point answer , the answer should be next greater integer.

Constraints:
1<=T<=100
2<=N<=20

0<=A[i]<=10^9


Example:
INPUT:
4
3
1 2 3
4
1 3 9 27
4
2 3 5 8
3
2 5 6

OUTPUT:
4
81
13
-99999

** For More Input/Output Examples Use 'Expected Output' option **

Author: Mukesh Kumar 5


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.