medium10 pts · first answer countsdynamic-programmingkadanedebugging
Kadane on all-negative numbers
This Kadane version returns 0 for [-3, -1, -2], but the answer should be -1 since the block cannot be empty. What is the fix?
let best = 0, cur = 0
for (const x of a) {
cur = Math.max(0, cur + x)
best = Math.max(best, cur)
}Discussion 0
Join free to post in the discussion.
Related questions
- What a 504 from Nginx meansBackend Developer
- Python default list surpriseBackend Developer
- Signs that a problem suits DPBackend Developer
- What memoisation meansBackend Developer
- What tabulation meansBackend Developer
- Cost of plain recursive FibonacciBackend Developer
- Fibonacci after adding a cacheBackend Developer
- Recursion with no base caseBackend Developer