diff --git a/tsst.cpp b/tsst.cpp new file mode 100644 index 0000000..2cc1fe2 --- /dev/null +++ b/tsst.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +using namespace std; + +int maxSubarraySum(vector &arr) { + int res = arr[0]; + + // Outer loop for starting point of subarray + for(int i = 0; i < arr.size(); i++) { + int currSum = 0; + + // Inner loop for ending point of subarray + for(int j = i; j < arr.size(); j++) { + currSum = currSum + arr[j]; + + // Update res if currSum is greater than res + res = max(res, currSum); + } + } + return res; +} + +int main() { + vector arr = {2, 3, -8, 7, -1, 2, 3}; + cout << maxSubarraySum(arr); + return 0; +}