Skip to content

Instantly share code, notes, and snippets.

@PBlanco
Last active March 29, 2017 16:04
Show Gist options
  • Save PBlanco/86aa4ca64dfe17c6b5007d48c98beded to your computer and use it in GitHub Desktop.
Save PBlanco/86aa4ca64dfe17c6b5007d48c98beded to your computer and use it in GitHub Desktop.
Flight movie length checker interviewcake
//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