hard20 pts · first answer countsarrayskadanedebugging
Kadane returns 0 for all negatives
This Kadane implementation returns 0 for [-3, -1, -2]. What is the correct fix?
let best = 0, cur = 0
for (const x of nums) {
cur = Math.max(0, cur + x)
best = Math.max(best, cur)
}
return bestDiscussion 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