File tree 1 file changed +10
-4
lines changed
src/main/java/com/thealgorithms/slidingwindow 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 12
12
*
13
13
* @author Your Name (https://github.com/Chiefpatwal)
14
14
*/
15
- class SlidingWindow {
15
+ class MaxSumKSizeSubarray {
16
+
17
+ // Prevent instantiation
18
+ private MaxSumKSizeSubarray () {
19
+ }
16
20
17
21
/**
18
22
* This method finds the maximum sum of a subarray of a given size k.
19
23
*
20
24
* @param arr is the input array where the maximum sum needs to be found
21
25
* @param k is the size of the subarray
22
- * @return the maximum sum of the subarray of size k, or -1 if the array length is less than k
26
+ * @return the maximum sum of the subarray of size k
23
27
*/
24
- public static int maxSumKSizeSubarray (int [] arr , int k ) {
25
- if (arr .length < k ) return -1 ; // Edge case: not enough elements
28
+ public static int max_sum_k_size_subarray (int [] arr , int k ) {
29
+ if (arr .length < k ) {
30
+ return -1 ; // Edge case: not enough elements
31
+ }
26
32
27
33
int maxSum = 0 ;
28
34
int windowSum = 0 ;
You can’t perform that action at this time.
0 commit comments