Last active
December 25, 2020 14:28
-
-
Save akshat-fsociety/9ce7f169e7ec183c6ad7753d2cb5d128 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) | |
{ | |
FastReader s=new FastReader(); | |
int n = s.nextInt(); //accepting size of an array | |
int k = s.nextInt(); //no. of terms to add | |
int a[] = new int[n]; | |
for(int i=0; i<n; i++)a[i] = s.nextInt(); // inputting array | |
int maximum_sum = Integer.MIN_VALUE; | |
for(int i=0; i< n-k+1; i++){ | |
int curr_sum = 0; | |
for(int j=0; j<k; j++){ | |
curr_sum = curr_sum + a[i + j]; | |
//updating the maximum_sum | |
maximum_sum = Math.max(curr_sum, maximum_sum); | |
}//end of j for loop | |
} // end of i for loop | |
System.out.println(maximum_sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment