Skip to content

Instantly share code, notes, and snippets.

@manojnaidu619
Created July 7, 2019 04:22
Show Gist options
  • Save manojnaidu619/5d56d26c912afad9e6033bf5d0ec4a2a to your computer and use it in GitHub Desktop.
Save manojnaidu619/5d56d26c912afad9e6033bf5d0ec4a2a to your computer and use it in GitHub Desktop.
Leetcode solution for contest problem "Corporate Flight Bookings" in Ruby
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