Zulu encounters a Sequence Problem
Practice
3.4 (26 votes)
Approved
Data structures
Easy
Implementation
One Dimensional
Problem
55% Success 6467 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Zulu is good in maths. He loves to play with numbers. One day while browsing through a book, he encountered a nice problem. In the problem, he was given an array A of N numbers.

For each index i in the array we define two quantities. Let r be the maximum index such that \(r>=i\) and sub-array from i to r (inclusive) is either non-decreasing or non-increasing. Similarly, let l be the minimum index such that \(l<=i\) and sub-array from l to i (inclusive) is either non-decreasing or non-increasing. Now, we define points of an index i to be equal to \(max(|A_i - A_l|,|A_i - A_r|)\). Note that l and r can be different for each index i.

The task of the problem is to find the index of the array A which have the maximum points.

Since the problem seems a bit harder, Zulu is struck. Can you solve this problem for Zulu?

Input:

In the first line of input, \(TEST\) will be given which is the number of test cases. For each of the test case, a single integer N will be given in the first line. In the second line, N space separated integers will be provided.

Output:

For each of the test cases, output the points of the index which have maximum points in the array in a separate line.

Constraint:

  • \(1 \le TEST \le 5\)

  • \(1 \le N \le 2*10^5\)

  • \( -2 * 10^{9} \le A[i] \le 2 * 10^{9} \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
131 votes
Tags:
Ad-HocBasic ProgrammingEasy
Points:20
31 votes
Tags:
ArraysData Structures1-DMath
Points:20
65 votes
Tags:
ArraysC++1-DData StructuresGreedy AlgorithmsBasics of Greedy AlgorithmsMath