MaxIntervalCover is a lightweight JavaScript library for solving the maximum interval coverage problem.
It finds the subset of intervals that maximizes the total covered length while ensuring no overlaps,
with an additional tie-break rule preferring fewer intervals when lengths are equal.
Features
Handles both half-open[a, b) and closed[a, b] intervals
Accepts input as {a, b} objects or [a, b] arrays
Drops zero-length and invalid intervals automatically
Finds an optimal non-overlapping subset of intervals:
Maximizes the total covered length
On ties, prefers fewer intervals
Efficient O(n log n) algorithm based on dynamic programming and binary search
Works with fractional and very large interval endpoints
true: Intervals are half-open [a, b) → touching intervals allowed
false: Intervals are closed [a, b] → touching intervals forbidden
Returns: Array of chosen intervals (subset of input).
Coding Style
Like all my libraries, MaxIntervalCover is written to minimize size after compression
with Google Closure Compiler in advanced mode. The code style is optimized to maximize compressibility.
If you extend the library, please preserve this style.
Building the library
After cloning the Git repository run:
npm installnpm run build
Run Tests
npm test
Copyright and Licensing
Copyright (c) 2025, Robert Eisele
Licensed under the MIT license.