Created
December 11, 2015 02:06
-
-
Save Hamled/d6f1defdbe50962b068b 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
def find_movies(flight_length, movie_lengths) | |
movie_complements = Set.new | |
movie_lengths.each do |movie_length| | |
# We have a good movie pair if this length is the complement of a previous movie's length | |
return true if movie_complements.include? movie_length | |
# Otherwise, track the complement of this movie's length for checking against succeeding movie lengths | |
movie_complements << (flight_length - movie_length) | |
end | |
# We didn't find any movie pairs | |
return false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment