Skip to content

Commit 59dd494

Browse files
committed
Your commit message here
1 parent 780de0b commit 59dd494

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main/java/com/thealgorithms/slidingwindow/maxSumKSizeSubarray.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@
1212
*
1313
* @author Your Name (https://github.com/Chiefpatwal)
1414
*/
15-
class SlidingWindow {
15+
class MaxSumKSizeSubarray {
16+
17+
// Prevent instantiation
18+
private MaxSumKSizeSubarray() {
19+
}
1620

1721
/**
1822
* This method finds the maximum sum of a subarray of a given size k.
1923
*
2024
* @param arr is the input array where the maximum sum needs to be found
2125
* @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
2327
*/
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+
}
2632

2733
int maxSum = 0;
2834
int windowSum = 0;

0 commit comments

Comments
 (0)