diff --git a/Solutions/Sliding Window Technique.cpp b/Solutions/Sliding Window Technique.cpp new file mode 100644 index 0000000..7389867 --- /dev/null +++ b/Solutions/Sliding Window Technique.cpp @@ -0,0 +1,50 @@ +#include +using namespace std; + +// Returns maximum sum in a subarray of size k +int max_sum(int arr[], int n, int k) +{ + // n must be greater + if(nn;i++) + { + win_sum+=(arr[i]-arr[i-k]); + max_sum=max(max_sum,win_sum); + } + return max_sum; +} + +int main() +{ + int size; + cout<<"Enter the size of the array:"; + cin>>size; + int arr[size]; + cout<<"Enter the elements of the array : "; + for(int i=0;i>arr[i]; + } + int win_size; + cout<<"Enter the size of the window: "; + cin>>win_size; + cout<<"The max sum is : "<