Associated Course(s):
DSA-Self Paced with Doubt Assistance
Placement 100

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.

ShubhamJain18 | 205 |

makeitdonesolo | 140 |

lost_found | 124 |

maggiiiii | 118 |

SahatPrasad1 | 108 |

Bishnu Dev Panda | 777 |

okayboss | 551 |

ShubhamJain18 | 516 |

yk12 | 514 |

makeitdonesolo | 480 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.