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.

murli01 | 343 |

decoder_101 | 216 |

Sulagna | 189 |

kya_bolti_public | 172 |

madhursengar24 | 172 |

PiyushPandey4 | 717 |

john_wick | 681 |

ASWATHAMA | 565 |

akhyasharma01 | 547 |

jagrit_ | 507 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.