Requirements
- Given an
ArrayList<int> containing movie runtimes in minutes and a target flight length, identify a pair whose runtimes add up to the target.
- Return the two indices, or return the two runtime values if that is the agreed interview contract; clarify which form is required.
- Account for an empty list, the absence of any matching pair, and multiple possible matches. The usual expectation is to report the first valid pair.
A compatible signature is:
pair<int, int> findPair(ArrayList<int> runtimes, int target)
If no matching pair exists, use the interviewer's specified no-result representation.
Examples
runtimes = [90, 85, 75, 60, 120, 150, 125]
target = 720 # 12 hours in minutes
# Output: no pair
# 600 + 120 is unavailable because 600 is not in the list; 720 is not itself a pair of elements.
runtimes = [120, 600]
target = 720
# Output: (0, 1)
# The runtimes at indices 0 and 1 total 720 minutes.
runtimes = [30, 40, 50]
target = 90
# Output: (1, 2)
# The values 40 and 50 add up to the target.
Notes
- The related Amazon in-flight-movies question is commonly associated with LC 1010, where pairs are selected according to durations divisible by 60; this version instead applies the same complementary-value idea to an arbitrary target.
- Possible extensions include finding every pair while handling duplicates, requiring the pair sum to leave a 30-minute advertising buffer, and extending the task to three movies.
- This question was reportedly used alongside an AI-assisted coding round that included a line-intersection problem.
Preparation
- Review LC 1 (Two Sum) and LC 1099 (Two Sum Less Than K) as nearby practice problems.
- Rehearse the duplicate-handling extension in which all unique pairs must be returned.
- Practice the buffer variation, which asks for the largest pair sum no greater than the target.