Created
January 23, 2018 13:50
-
-
Save vajapravin/beb33ebbc6a1cf0d9b1f3aa32947fca5 to your computer and use it in GitHub Desktop.
This file contains 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
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