You are given array **A **of size** n**. You need to find the maximum-sum sub-array with the condition that you are allowed to skip at most one element.

**Input Format:**

The first line of input contains an integer **T** denoting the number of test cases. The description of** T** test cases follows. The first line of each test case contains a single integer **n** denoting the size of array. The second line contains n space-separated integers A_{1}, A_{2}, ..., A_{n} denoting the elements of the array.

**Output Format:**

For each test case, in a new line, print the maximum sum.

**Your Task:**

This is a function problem. The driver code takes input. Your task is to complete the function **maxSumSubarray** that take array and size as parameters and returns the maximum sum.

**Constraints:**

1 <= T <= 100

1 <= n <= 100

-10^{3} <= A_{i}<= 10^{3}

**Example:
Input:**

2

5

1 2 3 -4 5

8

-2 -3 4 -1 -2 1 5 -3

**Output:**

11

9

**Explanation:
Testcase1:**

We can get maximum sum subarray by skipping -4.

We can get maximum sum subarray by skipping -2 as [4, -1, 1, 5] sums to 9, which is the maximum achievable sum.

Author: Shubham Joshi 1

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.

hari32147 | 100 |

AtakanSarıoğlu | 83 |

geetyadav | 82 |

amitpandey19 | 81 |

AdityaRaj9 | 75 |

abducodes | 862 |

harshtyagi36 | 425 |

vamsikrishna55 | 323 |

sandipbhaumik | 321 |

arpit_anshuman | 319 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.