16_ticket_translation.rb
# Assumes without checking that input intervals are sorted by start time.
Assumes without checking that input intervals are sorted by start time.
Assumes without checking that input intervals are sorted by start time .
def merge_intervals(intervals)
  prev_min, prev_max = intervals.first
  intervals.each_with_object([]) { |r, merged|
    min, max = r
    if min > prev_max
      merged << [prev_min, prev_max]
      prev_min, prev_max = r
    else
      prev_max = [prev_max, max].max
    end
  } << [prev_min, prev_max]
end
def merge_intervals ( intervals ) prev_min , prev_max = intervals . first intervals . each_with_object ( [ ] ) { | r , merged | min , max = r if min > prev_max merged << [ prev_min , prev_max ] prev_min , prev_max = r else prev_max = [ prev_max , max ] . max end } << [ prev_min , prev_max ] end
Assumes without checking that input intervals are sorted by start time.
Assumes without checking that input intervals are sorted by start time .
intervals
<not_specific>