Skip to content

Instantly share code, notes, and snippets.

@vajapravin
Created January 23, 2018 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vajapravin/beb33ebbc6a1cf0d9b1f3aa32947fca5 to your computer and use it in GitHub Desktop.
Save vajapravin/beb33ebbc6a1cf0d9b1f3aa32947fca5 to your computer and use it in GitHub Desktop.
prob1.rb
def getUserInput
gets.chomp.split(" ").map(&:to_i)
end
total_stops, vacant_seats = getUserInput
standing_stops = 0
(total_stops-1).downto(1) do |s|
stop = getUserInput
vacant_seats += (stop[1] - stop[0])
standing_stops += 1 if vacant_seats.eql?(0)
end
print standing_stops
prob2.rb
def getUserInput
gets.chomp.split(" ").map(&:to_i)
end
n, k = getUserInput
a = getUserInput
c = a.combination(2).to_a
print c.collect{|i| i.sort.reverse.inject(:-)}.sort[n-1]
prob3.rb
def getUserInput
gets.chomp.split(" ").map(&:to_i)
end
size = gets.chomp.to_i
elements = getUserInput
occurances = gets.chomp.to_i
print elements.select{|i| elements.count(i) == occurances}.min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment