Maximum bitonic subarray sum
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.

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

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.

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.