Created
July 7, 2019 04:22
-
-
Save manojnaidu619/5d56d26c912afad9e6033bf5d0ec4a2a to your computer and use it in GitHub Desktop.
Leetcode solution for contest problem "Corporate Flight Bookings" in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def corp_flight_bookings(bookings, n) | |
min_max = [] | |
return bookings if bookings.empty? or bookings[0].empty? | |
bookings.each do |i| | |
min_max << i[0] << i[1] | |
min_max << 1 if i[0]!=1 and i[1]!=1 | |
end | |
min_max.sort! | |
min_max.uniq! | |
min = min_max.first | |
max = min_max.last | |
min_max.clear | |
for x in min..max do | |
min_max << x | |
end | |
sum=0 | |
out = [] | |
min_max.each do |x| | |
bookings.each do |y| | |
if x.between?(y[0],y[1]) | |
sum+=y[2] | |
end | |
end | |
out << sum | |
sum = 0 | |
end | |
p out | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment