What is wrong in this code? Not able to find it


#1

public class Solution {
public int solve(ArrayList A, int B) {
Deque dq1 = new ArrayDeque(B);
int sum = 0;
for(int i=0; i<B; i++)
{
sum += A.get(i);
dq1.addLast(A.get(i));
}
int max = Integer.MIN_VALUE;
int n = A.size()-1;
for(int i=0;i<B;i++)
{
max = Math.max(max, sum);
sum = sum - dq1.removeLast();
sum = sum + A.get(n-i);
dq1.addFirst(A.get(n-i));
}
return max;
}
}