Category: Kadane

Maximum subarray sum possible after removing at most one subarray

import java.io.*;import java.util.*;  class GFG {                  public static void maximumSum(        int arr[], int n)    {        long[] preSum = new long[n];          long sum = 0;        long maxSum = 0;                  for (int i = 0; i < n; i++) {                          sum = Math.max(arr[i],                           sum + arr[i]);                          maxSum = Math.max(maxSum,                              sum);                          preSum[i] = maxSum;        }          sum = 0;        maxSum = 0;          long[] postSum = new long[n + 1];                  for (int i = n - 1; i […]

Continue Reading

Print all strings corresponding to elements in a subarray with maximum absolute sum

   #include using namespace std;    void maximumAbsSum(pair* arr,                    int N) {     int start = 0, end = 0, res = 0,         negIndex = 0, posIndex = 0,         negPrefix = 0, posPrefix = 0;             for (int i = 0; i < N; i++) {            if (arr[i].second < 0) {                              […]

Continue Reading