diff --git a/Coding/Window Sliding Technique.cpp b/Coding/Window Sliding Technique.cpp new file mode 100644 index 00000000..96a5e4e8 --- /dev/null +++ b/Coding/Window Sliding Technique.cpp @@ -0,0 +1,35 @@ +// O(n*k) solution for finding maximum sum of +// a subarray of size k +#include +using namespace std; + +// Returns maximum sum in a subarray of size k. +int maxSum(int arr[], int n, int k) +{ + // Initialize result + int max_sum = INT_MIN; + + // Consider all blocks starting with i. + for (int i = 0; i < n - k + 1; i++) { + int current_sum = 0; + for (int j = 0; j < k; j++) + current_sum = current_sum + arr[i + j]; + + // Update result if required. + max_sum = max(current_sum, max_sum); + } + + return max_sum; +} + +// Driver code +int main() +{ + int arr[] = { 1, 4, 2, 10, 2, 3, 1, 0, 20 }; + int k = 4; + int n = sizeof(arr) / sizeof(arr[0]); + cout << maxSum(arr, n, k); + return 0; +} + +// This code is contributed by Aditya Kumar (adityakumar129) diff --git a/Matrix multiplication in C++.cpp b/Matrix multiplication in C++.cpp new file mode 100644 index 00000000..a080f5bc --- /dev/null +++ b/Matrix multiplication in C++.cpp @@ -0,0 +1,48 @@ +#include +using namespace std; +int main() +{ +int a[10][10],b[10][10],mul[10][10],r,c,i,j,k; +cout<<"enter the number of row="; +cin>>r; +cout<<"enter the number of column="; +cin>>c; +cout<<"enter the first matrix element=\n"; +for(i=0;i>a[i][j]; +} +} +cout<<"enter the second matrix element=\n"; +for(i=0;i>b[i][j]; +} +} +cout<<"multiply of the matrix=\n"; +for(i=0;i