npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

kadanes-algo

v1.0.3

Published

A powerful JavaScript package with 40+ Kadane’s Algorithm variations.

Downloads

45

Readme

kadanes-algo

A powerful JavaScript package with 40+ variations of Kadane’s Algorithm to solve various subarray problems.

Features

✅ 40+ optimized Kadane’s Algorithm implementations

✅ Handles maximum sum subarrays, subsequences, XOR subarrays, modulo constraints, and more

✅ Efficient solutions with linear or near-linear time complexity

✅ No dependencies – lightweight and fast

Installation

npm i kadanes-algo

Importing

For CommonJS (Node.js Default)

const kadanes = require('kadanes-algo');

For ES Modules (ECMAScript Imports)

import kadanes from 'kadanes-algo';

Usage Examples

Find the Maximum Sum Subarray

const kadanes = require('kadanes-algo');

const arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4];
console.log(kadanes.maxSubarraySum(arr));       
// Output: 6 (subarray: [4, -1, 2, 1])

Find the Maximum Sum in a Circular Array

const kadanes = require('kadanes-algo');

const arr = [8, -1, 3, 4];
console.log(kadanes.maxCircularSubarraySum(arr));  
// Output: 15 (subarray: [8, -1, 3, 4])

Find Maximum XOR Subarray

const kadanes = require('kadanes-algo');

const arr = [8, 1, 2, 12, 7, 6];
console.log(kadanes.maxXORSubarray(arr));  
// Output: 15

Find the Maximum Sum of Two Non-Overlapping Subarrays

const kadanes = require('kadanes-algo');

const arr = [3, 8, 1, 9, 6, 7, 2, 5];
console.log(kadanes.maxTwoNonOverlappingSubarrays(arr, 2, 3));  
// Output: 33

Find the Longest Subarray with a Given Sum

const kadanes = require('kadanes-algo');

const arr = [1, 2, 3, 7, 5];
console.log(kadanes.longestSubarrayWithSum(arr, 12));  
// Output: [2, 3, 7] (subarray that sums to 12)

API Reference

| Function Name | Description | |--------------------------------------|-------------------------------------------------------| | allMaxSubarrays(arr) | Finds all maximum sum subarrays | | countMaxSumSubarrays(arr) | Counts subarrays with the maximum sum | | longestPositiveSubarray(arr) | Finds the longest contiguous positive subarray | | longestSubarrayWithSum(arr, target) | Returns the longest subarray with sum equal to target | | max3DSubmatrixSum(matrix) | Finds the max sum in a 3D matrix | | maxSubarraySum(arr) | Finds the maximum sum of any contiguous subarray | | minSubarraySum(arr) | Finds the minimum sum subarray | | maxAbsoluteSubarraySum(arr) | Finds the maximum absolute sum of any subarray | | maxAlternatingSubarraySum(arr) | Finds the max sum with alternating signs | | maxAverageSubarray(arr, k) | Finds the max average subarray of length k | | maxBinarySubarraySum(arr) | Finds the max sum in a binary array (0s & 1s) | | maxCircularSubarraySum(arr) | Finds the max sum in a circular array | | maxEvenOddSubarraySum(arr) | Finds the max sum subarray with alternating even-odd elements | | maxIncreasingSubarraySum(arr) | Finds the max sum of a strictly increasing subarray | | maxNonAdjacentSubarraySum(arr) | Finds the max sum where no two selected elements are adjacent | | maxProductSubarray(arr) | Finds the maximum product subarray | | maxSlidingWindowKadane(arr, k) | Finds the max sum in a sliding window of size k | | maxSubarray(arr) | Finds the maximum subarray | | maxSubarrayKConcat(arr, k) | Finds max sum in an array repeated k times | | maxSubarrayKConcatSum(arr, k) | Finds max sum in an array repeated k times | | maxSubarrayRangeQuery(arr) | Finds the max sum in a range query | | maxSubarrayReplacingNegatives(arr) | Finds the max sum after replacing negatives | | maxSubarraySumInRotatedArray(arr) | Finds the max sum in a rotated array | | maxSubarraySumModulo(arr) | Finds the max sum with modulo constraints | | maxSubarraySumSkippingK(arr) | Finds the max sum skipping k elements | | maxSubarraySumWithKDeletions(arr) | Finds the max sum with k deletions | | maxSubarraySumWithKModifications(arr)| Finds the max sum with k modifications | | maxSubarraySumWithOneDeletion(arr) | Finds the max sum with one deletion | | maxSubarraySumWithOneSplit(arr) | Finds the max sum with one split | | maxSubarraySumWithOneSwap(arr) | Finds max sum after one swap of two elements | | maxSubarrayWithDistinctElements(arr) | Finds the max sum with distinct elements | | maxSubmatrixSum(arr) | Finds the max sum in a submatrix | | maxSumIncreasingSubsequence(arr) | Finds the max sum increasing subsequence | | maxSumPathBetweenIndices(arr) | Finds the max sum path between indices | | maxSumPathInGrid(arr) | Finds the max sum path in a grid | | maxTwoNonOverlappingSubarrays(arr) | Finds the max sum of two non-overlapping subarrays | | maxWeightedSubarray(arr) | Finds the max weighted subarray | | maxXORSubarray(arr) | Finds the max XOR value of any contiguous subarray | | smallestMaxSubarray(arr) | Finds the smallest max subarray | | smallestSubarrayWithSumAtLeast(arr) | Finds the smallest subarray with sum at least |