Skip to content

renzrollon/merge-intervals-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Merge Intervals Java Project

This project demonstrates advanced interval algorithms and data structures in Java, using a spec-driven workflow powered by OpenSpec.

Features

1. Interval List Intersections

  • 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:

2. Count Integers in Intervals

  • 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 TreeMap in CountIntervals.java for O(log n) add and O(1) count.
  • Tested in: CountIntervalsTest.java
  • OpenSpec Artifacts:

How to Run

  • Requires Java 17+ and Maven.
  • Run all tests:
    mvn test

Project Structure

  • src/main/java/org/example/IntervalListIntersections.java — Static interval intersection algorithm
  • src/main/java/org/example/CountIntervals.java — Dynamic interval set with add/count
  • src/test/java/org/example/IntervalListIntersectionsTest.java — Unit tests for intersections
  • src/test/java/org/example/CountIntervalsTest.java — Unit tests for dynamic interval set
  • openspec/changes/archive/2026-04-18-interval-list-intersections/ — All OpenSpec artifacts for intersections
  • openspec/changes/archive/2026-04-18-count-integers-in-intervals/ — All OpenSpec artifacts for dynamic interval set

About OpenSpec

OpenSpec enables spec-driven development: every change is tracked from proposal to design, specs, tasks, and implementation, with full traceability and testability.

About

Exercise for merge-intervals pattern using Java and Spec Driven Development

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages