You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Given an array of integers Arr of size N and a number K. Return the maximum sum of a subarray of size K.
// code in c++
int maximumSumSubarray(int K, vector<int> &A , int N){
int i = 0; // starting point of window
int maxi = 0, s = 0;
for(int j = 0; j < N; j++){
s += A[j];
if(j - i + 1 == K){ // when length of subarray becomes equal to K
maxi = max(maxi, s);
s -= A[i];
i += 1;
}
}
return maxi;
}
// Sliding window technique is useful for solving problems in array or string, especially it is considered as a technique that could reduce the time complexity from O(n²) to O(n).