title: Maximum Subarray Sum Using Prefix Sum
signature: function maximumSubarraySumUsingPrefixSum($arr, $n) {
source_py: def maximum_subarray_sum_using_prefix_sum(arr, n):
      min_prefix_sum = 0
      res = (- math.inf)
      prefix_sum = []
      prefix_sum.append(arr[0])
      for i in range(1, n):
          prefix_sum.append((prefix_sum[(i - 1)] + arr[i]))
      for i in range(n):
          res = max(res, (prefix_sum[i] - min_prefix_sum))
          min_prefix_sum = min(min_prefix_sum, prefix_sum[i])
      return res
source_cpp: int maximum_subarray_sum_using_prefix_sum(vector<int> arr, int n) {
    int min_prefix_sum = 0;
    int res = numeric_limits < int > :: min ( );
    int prefix_sum [ n ];
    prefix_sum [ 0 ] = arr [ 0 ];
    for ( int i = 1;
    i < n;
    i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ];
    for ( int i = 0;
    i < n;
    i ++ ) {
      res = max ( res, prefix_sum [ i ] - min_prefix_sum );
      min_prefix_sum = min ( min_prefix_sum, prefix_sum [ i ] );
    }
    return res;
  }