Skip to content
RED SAG Skills
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 best
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions