
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
maximal-sum
Advanced tools
It provides two functions to get the job done. Both of them calculate sum of contiguous subarray of an array where the subarray produces maximum possible sum.
For example
expect(getMaxSubSum([-1, 2, 3, -9])).toBe(5);
expect(getMaxSubSum([2, -1, 2, 3, -9])).toBe(6);
expect(getMaxSubSum([-1, 2, 3, -9, 11])).toBe(11);
expect(getMaxSubSum([-2, -1, 1, 2])).toBe(3);
expect(getMaxSubSum([100, -9, 2, -3, 5])).toBe(100);
expect(getMaxSubSum([1, 2, 3])).toBe(6);
npm i maximal-sum
getMaxSubSum
const { getMaxSubSum } = require('maximal-sum');
const sum = getMaxSubSum([2, -1, 2, 3, -9]);
// > 6
// The subarray is [2, -1, 2, 3]
Use this method to have O(n)
complexity. The concept is simple:
0
;0
;current
. If it becomes < 0
, then override to 0
.
b. maximum
is the greatest between maximum
and current
.It works because, we don't actually want to get the subarray itself. Just the
sum. Also when comparing current
with maximum
, if at some point, the sum
becomes greater, starting from an index !== 0
, we override at 3.b
.
getMaxSubSumBrute
Just for testing purpose. It produces the same result but has worst performance. The reason is, it uses nested loops to brute-force all possible subarrays and checks for the maximum of sums.
const { getMaxSubSumBrute } = require('maximal-sum');
const sum = getMaxSubSumBrute([2, -1, 2, 3, -9]);
// > 6
// The subarray is [2, -1, 2, 3]
FAQs
Get maximal sum of contiguous subarray of an array.
The npm package maximal-sum receives a total of 1 weekly downloads. As such, maximal-sum popularity was classified as not popular.
We found that maximal-sum demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.