Skip to main content
All questions
EasyArrays · Hash Set

Two Movies for the Flight

Written by a community member · · 1 attempt · 0% pass

0

Given an integer flight_length and a list of integer movie_lengths, determine whether two different movies have runtimes that add up to exactly flight_length. Return True if such a pair exists, and False otherwise.

You must choose exactly two movies, and you may not choose the same list entry twice. If two separate entries have the same runtime, they count as two different movies. Favor runtime efficiency over memory usage.

Constraints: 0 <= len(movie_lengths) <= 100_000; 1 <= movie_lengths[i] <= 10_000; 1 <= flight_length <= 20_000.

Example 1: flight_length = 120, movie_lengths = [90, 30, 60, 110, 40] returns True because 90 + 30 = 120.

Example 2: flight_length = 90, movie_lengths = [45] returns False; a single movie cannot be selected twice.