This project demonstrates advanced interval algorithms and data structures in Java, using a spec-driven workflow powered by OpenSpec.
- Problem: Given two lists of closed, sorted, non-overlapping intervals, compute all their intersections.
- Solution: Implements a two-pointer O(m+n) algorithm in
IntervalListIntersections.java. - Tested in:
IntervalListIntersectionsTest.java - OpenSpec Artifacts:
- Problem: Design a data structure to add intervals and count the number of distinct integers covered.
- Solution: Implements a dynamic merge-intervals pattern using a
TreeMapinCountIntervals.javafor O(log n) add and O(1) count. - Tested in:
CountIntervalsTest.java - OpenSpec Artifacts:
- Requires Java 17+ and Maven.
- Run all tests:
mvn test
src/main/java/org/example/IntervalListIntersections.java— Static interval intersection algorithmsrc/main/java/org/example/CountIntervals.java— Dynamic interval set with add/countsrc/test/java/org/example/IntervalListIntersectionsTest.java— Unit tests for intersectionssrc/test/java/org/example/CountIntervalsTest.java— Unit tests for dynamic interval setopenspec/changes/archive/2026-04-18-interval-list-intersections/— All OpenSpec artifacts for intersectionsopenspec/changes/archive/2026-04-18-count-integers-in-intervals/— All OpenSpec artifacts for dynamic interval set
OpenSpec enables spec-driven development: every change is tracked from proposal to design, specs, tasks, and implementation, with full traceability and testability.