Amazon Online Assessment 2019 - Two sum closest

I had 2 question on my online assesment, however I remeber only the first one. My code passed only 10 test out of 13.
If anyone want to share their way of implementation.
I did a sorting and then found the best pair with 2 for loops

  1. Movies on Flight
    You are on a flight and wanna watch two movies during this flight.
    You are given int[] movie_duration which includes all the movie durations.
    You are also given the duration of the flight which is d in minutes.
    Now, you need to pick two movies and the total duration of the two movies is less than or equal to (d - 30min).
    Find the pair of movies with the longest total duration. If multiple found, return the pair with the longest movie.

Example 1:

Input: movie_duration = [90, 85, 75, 60, 120, 150, 125], d = 250
Output: [90, 125]
Explanation: 90min + 125min = 215 is the maximum number within 220 (250min - 30min)

这道题跟Leetcode 1099类似,sort完以后用反向双指针只需要扫一遍就可以了