From 7ec89a964b8ad0b1541d68757650cc1775155850 Mon Sep 17 00:00:00 2001 From: PrerikaPandit <44524021+PrerikaPandit@users.noreply.github.com> Date: Sat, 27 Oct 2018 17:18:38 +0530 Subject: [PATCH] Add files via upload --- kadanes_algorithm.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 kadanes_algorithm.cpp diff --git a/kadanes_algorithm.cpp b/kadanes_algorithm.cpp new file mode 100644 index 0000000..8a514dd --- /dev/null +++ b/kadanes_algorithm.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; + +int main(){ + int n; + cin>>n //size of the array + int *arr = new int[n]; + + for(int i=0; i>arr[i]; + int maxSoFar = INT_MIN, maxEndingHere = 0; + for(int i=0; i maxSoFar) + maxSoFar = maxEndingHere; + if(maxEndingHere < 0) + maxEndingHere = 0; + } + return maxSoFar; +} \ No newline at end of file