Skip to content

Instantly share code, notes, and snippets.

@mchail
Last active August 29, 2015 14:11
Show Gist options
  • Save mchail/f81828c708aecbb79f4d to your computer and use it in GitHub Desktop.
Save mchail/f81828c708aecbb79f4d to your computer and use it in GitHub Desktop.
Interval merger
class IntervalMerger
def initialize(*intervals)
@intervals = intervals
end
def merge
# TODO: return the reduced set of intervals
end
end
IntervalMerger.new([0, 2], [1, 4]).merge # => [[0, 4]]
IntervalMerger.new([0, 1], [3, 4]).merge # => [[0, 1], [3, 4]]
IntervalMerger.new([4, 5], [5, 6], [6, 7]).merge # => [[4, 7]]
IntervalMerger.new([4, 5], [2, 6]).merge # => [[2, 6]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment