Find Maximum Subarray Sum
Send Feedback
You are given an integer array, arr, of size N and a positive integer K. Out of all subarrays of 'arr' of size K, find the sum of the subarray that has the maximum sum.
Input format:
Output format:
Constraints:
Sample Input 1:
Sample Output 1:
Sample Input 2:
Sample Output 2:
Explanation for Sample Output 2:
import java.util.*; public class Solution { public static void main(String[] args) { // Write your code here Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int k = scanner.nextInt(); int[] arr = new int[n]; for (int i=0;i< arr.length;i++) arr[i]=scanner.nextInt(); int sum=0,max=Integer.MIN_VALUE; for (int i=0;imax) max=sum; sum=0; } System.out.println(max); } }