Dsa
Dynamic Programming
Medium
Maximum Subarray Modifications
You are given an array of integers. You can perform a modification operation on the array, which consists of changing one element to any integer of your choice. Your goal is to maximize the sum of the longest contiguous subarray after performing exactly one modification. Write a function that reads the array from standard input and prints the maximum possible sum after one modification.
Input Format:
- The first line contains an integer n (1 ≤ n ≤ 10^6), the size of the array.
- The second line contains n integers a_i (−10^4 ≤ a_i ≤ 10^4), the elements of the array.
Output Format:
- Output a single integer, the maximum sum of the longest contiguous subarray after one modification.
Example:
Input:
5
1 -2 0 3 -1
Output:
4
Key concepts
dynamic_programmingsubarraysgreedy
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now