Given a unsorted array, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i < j, calculate maximum of | A[i] - A[j] | + | i - j |.
Input: The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains N where N is the size of array. The second line of each test case contains N space separated integers denoting the array elements.
Output: For each testcase in the new line, print the maximum diiference as given in question.
1 <= T <= 100
1 <= N <= 106
0 <= |A[i]| <= 106
1 3 -1
Testcase 1: Maximum difference comes from indexes 1, 2 i.e | 3 - (-1) | + | 1 - 2 | = 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.