You’re building a feature for choosing 2 movies whose total run times will equal the exact length of a flight. Write a method that takes an integer flightLength (in minutes) and an array of integers movieLengths (in minutes) and returns a boolean indicating whether there are two numbers in movieLengths whose sum equals flightLength - in other words, determine if there are two movies you can watch such that you spend the entire flight watching movies.
flightLength = 6
movieLengths = [1, 2, 4, 5]
<!-- [1,2]
[1,4]
[1,5] -->
...
flightlength
# Calculate the difference between flight length and each of the elements in movieLengths
temp = [5, 4, 2, 1]
```java
public boolean main(int fl, int[] ml) {
// int flightLength = fl;
// List ml = ml;
// List temp = new ArrayList<Integer>();
// for (each element in ml) {
// store fl - ml to temp
// }
// Result: [fl - ml1, fl - ml2, fl - ml3 ...]
// [1, 2, 4, 5]
// [5, 4, 2, 1]
Map<Integer, Integer> temp = new HashMap<>();
// for loop populates the map with both the differences of fl and elements of ml to the ml's elements themselves
for (iterate until end of length of ml) {
int difference = fl - ml[i]
if (temp.containsKey(difference)){
return true
}
map.put(param1, param2)
map.put(ml[i], i)
}
return false
}