flights holds flight durations in hours. A traveller wants to take two different flights back to back (with no layover) and land at the same time of day they set off, which means the total duration must be a multiple of 24 hours.
Return the number of index pairs i < j for which flights[i] + flights[j] is divisible by 24.
The array can be very long, so checking every pair will not work.flights=[7, 17, 12, 36, 31] → 3
7 + 17 = 24, 12 + 36 = 48 and 17 + 31 = 48: three pairs.
flights=[20, 4, 28, 44] → 4
20 + 4, 20 + 28, 4 + 44 and 28 + 44 are all multiples of 24.
flights=[1, 2] → 0
3 hours is not a whole number of days.
flights=[7, 17, 12, 36, 31]
3
Run checks the first 3 tests in your browser. Submit checks all 74 tests on the server, hidden ones included.