Last active
March 29, 2017 16:04
-
-
Save PBlanco/86aa4ca64dfe17c6b5007d48c98beded to your computer and use it in GitHub Desktop.
Flight movie length checker interviewcake
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
//https://www.interviewcake.com/question/python/inflight-entertainment | |
const flightLength = 5 * 60; //minutes | |
const movieLengths = [30, 15, 12, 90, 17, 45] // movies length in minutes | |
function twoMoviesInListEqualFlightLength(flightLength, movieLengths) { | |
let needMovieOfLength = {}; | |
for (let i = 0; i < movieLengths.length; i++) { | |
let mlength = movieLengths[i]; | |
if (mlength in needMovieOfLength) { | |
return true; | |
} | |
let neededLength = flightLength - mlength; | |
needMovieOfLength[neededLength] = true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment