Educative

Unresolved error in IDE

Whenever I try to run the code it’s showing the following error:
{“errorText”: “failed to execute code”, “request_id”: “5ebcef6d00ff0ae9d24ed3a16a0001737e6564756361746976652d6865736976650001763230303530342d6d696e692d72656c656173652d3230303531332d3036333100010106”}

My Code:
class MaxSumSubArrayOfSizeK {
public static int findMaxSumSubArray(int k, int[] arr) {
int windowStart = 0;
int windowSum = 0;
int maxSum = 0;
for(int windowEnd = 0 ; windowEnd < arr.length-1; windowEnd++){

        windowSum = windowSum + arr[windowEnd];
       if(windowEnd >= k-1){
          maxSum = Math.max(windowSum,maxSum);
          windowSum = windowSum - arr[windowStart];
          windowStart++;
          
       }
       

    }
return maxSum;

}

public static void main(String[] args) {
System.out.println("Maximum sum of a subarray of size K: "
+ MaxSumSubArrayOfSizeK.findMaxSumSubArray(3, new int[] { 2, 1, 5, 1, 3, 2 }));
System.out.println("Maximum sum of a subarray of size K: "
+ MaxSumSubArrayOfSizeK.findMaxSumSubArray(2, new int[] { 2, 3, 4, 1, 5 }));
}
}

1 Like

@Palak Hi, I am facing the same issue. How was it resolved?