The Pointer Never Resets
a is sorted and has n elements. This is the whole loop:
int j = 0, best = 0;
for (int i = 0; i < n; i++) {
while (j < n && a[j] - a[i] <= K) j++;
best = max(best, j - i);
}
Counting only executions of j++, what is the worst case total across the entire run?
Sign in to answer questions and track your progress
Sign In