Maximum value of expression
Submissions: 554   Accuracy:

19.18%

  Difficulty: Easy   Marks: 2

Given an array of N positive integers. The task is to find maximum value of
|A[i] – A[j]| + |i – j|, where 0 <= i, j <= N – 1 and A[i], A[j] belong to the array.

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. First line of each test case contains an integer N and the second line contains N space separated array elements.

Output:
For each test case, print the maximum value of expression in array A[] in new line.

Constraints:
1<=T<=100
1<=N<=105
1<=A[i]<=105

Example:
Input:

2
4
1 2 3 1
3
1 1 1

Output:
4
2

Explanation:

Input : N = 4, A[] = { 1, 2, 3, 1 } 
Output : 4
Choose i = 0 and j = 2

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

Contributor: Arun Tyagi
Author: arun03


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.