The first line of input contains an integer 'T' representing the number of test cases. The first line of each test case contains a single integer ‘N’ denoting the size of the array. The second line of each test case contains ‘N’ space-separated integers denoting the elements of the array.
For each test case, return the length of the longest possible subsequence of the array that is in arithmetic progression. The output of each test case will be printed in a separate line.
1 <= T <= 5 1 <= N <= 50 1 <= ARR[i] <= 50 Where 'ARR[i]' is element of array at index 'i'. Time limit: 1 sec
The idea here is to check all possible common differences that a subsequence can have. We will generate all possible common differences by running two loops then we will try to find the longest subsequence using the current common difference and recursion.
The steps are as follows:
Description of ‘findAP’ function:
This function will take three parameters :
int findAP('INDEX', ‘DIFFERENCE’, ‘ARR’):