Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5646 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4716 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@skj7 | 671 |

@gurshehzadsingh | 418 |

@swastik8750 | 411 |

@nishunishuraj18 | 405 |

@vedantvalsangkar | 390 |

@deepakchowdary | 380 |

@akashverma4 | 369 |

@satyamannsm | 353 |

@2018uec1603 | 333 |

@rkrupeshkumar345 | 331 |

@surajmamgai | 330 |

Complete Leaderboard |

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.

**Example 1:**

**Input:
**n = 5
A[] = {1,2,3,-4,5}
**Output: **11**
Explanation: **We can get maximum sum
subarray by skipping -4.

**Example 2:**

**Input:
**n = 8
A[] = {-2,-3,4,-1,-2,1,5,-3}
**Output: **9**
Explanation: **We can get maximum sum
subarray by skipping -2 as [4,-1,1,5]
sums to 9, which is the maximum
achievable sum.

**Your Task:**

Your task is to complete the function **maxSumSubarray** that take array and size as parameters and returns the maximum sum.

**Expected Time Complexity: **O(N).

**Expected Auxiliary Space: **O(N).

**Constraints:**

1 <= n <= 100

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

Login to report an issue on this page.

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

Yes
Max sum subarray by removing at most one element

...