Associated Course(s):
DSA- Online
Geeks Classes in Noida- (Summer-Weekdays)

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.

bhatabhi554 | 317 |

hardikJain5 | 306 |

CodeBuddy | 293 |

Akkki111 | 233 |

clone | 230 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

mazumderrohit8 | 1176 |

RemoveTLE | 1144 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4605 |

Quandray | 4444 |

Login to report an issue on this page.