Simple C Code with 100% Time and Space
The idea is to keep the track of so far maximun sum including the previous number or excluding it.\n\nint max(int a, int b)\n{\n    return a>b?a:b;\n}\nint maxi
The idea is to keep the track of so far maximun sum including the previous number or excluding it.\n```\nint max(int a, int b)\n{\n    return a>b?a:b;\n}\nint maximumSum(int* arr, int arrSize){\n    int ans = arr[0];\n    int excl=0,incl=arr[0];\n    for(int i=1;i<arrSize;i++)\n    {\n        excl= max(excl+arr[i],incl);    //Taking which is maximum of previous including or the current + previous excluding\n        incl = max(arr[i],incl+arr[i]);    // Taking maximum of current element or previous including + current element\n        ans = max(ans,max(excl,incl)); //Keeping track of maximum so far\n    }\n    return ans;\n}\n```
[]