BETA

Difficulty Level: Medium

Submissions: 1084 Accuracy:

17.25%

Maximum bitonic subarray sum
     

Given an array containing N numbers. The task is to find the maximum sum bitonic subarray. A bitonic subarray is a subarray in which elements are first increasing and then decreasing. A strictly increasing or strictly decreasing subarray is also considered as bitonic subarray.

Time Complexity : O(n)
Auxiliary Space : O(1)

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 a integer N and the second line contains N space separated array elements.

Output:
For each test case, print the maximum bitonic subarray sum in new line.

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

Example:
Input:

2
7
5 3 9 2 7 6 4
7
5 4 3 2 1 10 6

Output:
19
17

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

Contributor: Arun Tyagi

Set Default Code

					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

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