https://practice.geeksforgeeks.org/problems/kadanes-algorithm/0

DP without array

class Solution {
public:
  int maxSubarraySum(int arr[], int n) {

    int sum = INT_MIN, currSum = 0, i = 0;

    while (i < n) {
      currSum += arr[i];
      sum = max(sum, currSum);

      if (currSum < 0)
        currSum = 0;
      i++;
    }
    return sum;
  }
};