Skip to content

feat: add merge intervals algorithm#14436

Open
inoovador wants to merge 1 commit intoTheAlgorithms:masterfrom
inoovador:add-merge-intervals
Open

feat: add merge intervals algorithm#14436
inoovador wants to merge 1 commit intoTheAlgorithms:masterfrom
inoovador:add-merge-intervals

Conversation

@inoovador
Copy link

Summary

  • Add a greedy algorithm implementation for merging overlapping intervals to greedy_methods/merge_intervals.py
  • The algorithm sorts intervals by start time then merges overlapping ones in a single pass (O(n log n) time complexity)
  • Includes 13 comprehensive doctests covering: normal merges, adjacent intervals, fully contained intervals, unsorted input, single/empty input, and input validation with proper error handling

Test plan

  • All 13 doctests pass (python -m doctest -v greedy_methods/merge_intervals.py)
  • ruff check passes with no issues
  • ruff format --check confirms proper formatting
  • Type hints included for function parameters and return value
  • CI/CD automated tests on GitHub Actions

🤖 Generated with Claude Code

Add a greedy algorithm implementation for merging overlapping intervals.
The algorithm sorts intervals by start time then merges overlapping ones
in a single pass, achieving O(n log n) time complexity.

Includes comprehensive doctests covering edge cases such as empty input,
single intervals, fully overlapping intervals, and input validation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants