I’ve solved the problem without using binary search and getting correct results when checked but when I submit it here, all the test cases are failing.
Can you check my code and let me know what’s wrong with it?
package Pratice2;
import java.util.Scanner;
public class five {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testCase = sc.nextInt();
for (int i = 0; i < testCase; i++) {
int len = sc.nextInt();
int stu = sc.nextInt();
long arr[] = new long[len];
long arraySum = 0;
long arraySumTwo = 0;
long ans = 0;
for (int j = 0; j < len; j++) {
long arrVal = sc.nextInt();
arr[j] = arrVal;
}
for (int j = 0; j < arr.length; j++) {
arraySum = arraySum +arr[j];
}
long avg = arraySum/stu;
for (int j = 0; j < arr.length; j++) {
arraySumTwo = arraySumTwo +arr[j];
if(arraySumTwo > avg) {
if(ans < arraySumTwo ) {
ans = arraySumTwo;
}
arraySumTwo = 0;
}
}
System.out.println(ans);
}
}
}