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 +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<