This work fine in given case but wrong here in test case ITs correct , Check it plzz


#1

public int solve(ArrayList A, int B) {
int max = -2147483648;
ArrayList arr = new ArrayList<>();
for (int i = B; i >0; i–) {
arr.add(A.get(i-1));

    }
    // System.out.println("Arr " + Arrays.toString(arr.toArray()));
    if (B > A.size() / 2) {

// System.out.println(“Greater”);
for (int i = B; i < A.size(); i++) {
arr.add(A.get(i));

        }

    } else {
        // System.out.println("Smaller");
         for (int i = B - 1; i < A.size(); i++) {
                arr.add(A.get(i));
                  }
    }

// System.out.println("Arr " + Arrays.toString(arr.toArray()));
// now calcualting

for (int i = 0; i < arr.size()-B+1; i++) {
int sum = 0;
for(int y=0;y<B;y++)sum = sum + arr.get(i+y);
// System.out.println("Sum is " + sum);
if(max<sum)max=sum;
}

    return max;
}