MCPcopy Create free account
hub / github.com/ashishps1/awesome-leetcode-resources / KadaneAlgorithm

Class KadaneAlgorithm

patterns/javascript/kadaneAlgorithm.js:1–12  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class KadaneAlgorithm {
2 maxSubArray(nums) {
3 let currentSum = nums[0];
4 let maxSum = nums[0];
5
6 for (let i = 1; i < nums.length; i++) {
7 currentSum = Math.max(nums[i], currentSum + nums[i]);
8 maxSum = Math.max(maxSum, currentSum);
9 }
10 return maxSum;
11 }
12}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected