From e615b8709dcd9db42a1a59e67668d3c6791c5c85 Mon Sep 17 00:00:00 2001 From: REETESH TOMAR <54767198+Reetesh-Tomar@users.noreply.github.com> Date: Tue, 18 Oct 2022 01:41:23 +0530 Subject: [PATCH 1/2] Added Kadane algo code in cpp --- algorithms/greedy/Kadane_Algorithm.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 algorithms/greedy/Kadane_Algorithm.cpp diff --git a/algorithms/greedy/Kadane_Algorithm.cpp b/algorithms/greedy/Kadane_Algorithm.cpp new file mode 100644 index 00000000..3a739d15 --- /dev/null +++ b/algorithms/greedy/Kadane_Algorithm.cpp @@ -0,0 +1,23 @@ +//Max subarray sum using Kadanes algorithm + +#include +using namespace std; + +int main() +{ + int arr_size; cin>>arr_size; + int arr[arr_size]; + for(int i=0;i>arr[i]; + + int ma=0,ans=INT_MIN; + for(int i=0;ians){ + ans=ma; + } + if(ma<0) ma=0; + } + cout< Date: Tue, 18 Oct 2022 01:42:51 +0530 Subject: [PATCH 2/2] Sliding Windows tech code in cpp --- .../dynamic-programming/Sliding Windows.cpp | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 algorithms/dynamic-programming/Sliding Windows.cpp diff --git a/algorithms/dynamic-programming/Sliding Windows.cpp b/algorithms/dynamic-programming/Sliding Windows.cpp new file mode 100644 index 00000000..155b7c5e --- /dev/null +++ b/algorithms/dynamic-programming/Sliding Windows.cpp @@ -0,0 +1,33 @@ +//////////////////////////////////////////////////////////////////// +///////////////WINDOW SLIDING TECHNIQUE///////////////////////////// +////ref- https://www.geeksforgeeks.org/window-sliding-technique///////////////////////////// +#include +using namespace std; +#define beastslayer ios_base::sync_with_stdio(false);cin.tie(NULL); +#define ll long long + +//Q- Find the maximum sum of a k length subarray from a given array + +int main() +{ + beastslayer; + + int arr[10]={5,1,-9,2,3,5,7,11,12,50}; + int k; //Length of subarrays + cin>>k; + + int max_sum=0; //Final answer to be found + for(int i=0;i