File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
src/main/java/com/thealgorithms/slidingwindow Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 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 ;
You can’t perform that action at this time.
0 commit comments