hard20 pts · first answer countsarrayssliding-windowdebugging
Bug in a minimum length window
This code should return the shortest length with sum >= target but returns a value that is too large for some inputs. What is wrong?
for (let r = 0; r < a.length; r++) {
sum += a[r]
if (sum >= target) {
best = Math.min(best, r - l + 1)
sum -= a[l++]
}
}Discussion 0
Join free to post in the discussion.
Related questions
- What a 504 from Nginx meansBackend Developer
- Python default list surpriseBackend Developer
- Cost of reading arr[i]Backend Developer
- Inserting at the front of an arrayBackend Developer
- Why push is amortized O(1)Backend Developer
- Changing one character of a stringBackend Developer
- Reversing a simple stringBackend Developer
- slice vs spliceBackend Developer