You have a truck moving around a circular track with gas stations spaced out around the circle. Each station has a finite amount of gas. The gas tank on the truck is infinit
static int getIndex(int A[], int B[]) {
int start = -1;
int N = A.length;
for (int i = 0; i < N; i++) {
int c = A[i] - B[i];
if (c >= 0) {
int j = i + 1;
while (c >= 0 && j < i + N) {
c += A[j % N] - B[j % N];
j++;
}
if (c >= 0) {
start = i;
break;
}
}
}
return start;
}