Medium Accuracy: 27.47% Submissions: 6194 Points: 4

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.

Explanation:
Test Case 1: {5 3 9 2 7 6 4}
All Bitonic Subarrays are as follows:
{5}, {3}, {9}, {2}, {7}, {6}, {4}, {5,3}, {3,9}, {9,2}, {2,7}, {7,6}, {6,4}, {3,9,2}, {2,7,6}, {7,6,4}, {2,7,6,4}.
Out of these, the one with the maximum sum is {2,7,6,4} whose sum is 19.