Song Duration Pairs Divisible by 60
Problem statement
Given a playlist of song durations in seconds, find pairs whose total duration is divisible by 60.
For this exercise, return every zero-based index pair [i,j] with i<j and (durations[i]+durations[j]) % 60 == 0. Distinct songs with equal durations still have distinct indices. Return pairs in lexicographic order: first by i, then by j. Return an empty list if none exist.
Function
songPairs(durations: int[]) → List<List<Integer>>Examples
Example 1
durations = [10,50,70,110]return = [[0,1],[0,3],[1,2],[2,3]]The valid index pairs are [0,1], [0,3], [1,2] and [2,3], with sums 60, 120, 120 and 180 seconds.
Example 2
durations = [60,60,60]return = [[0,1],[0,2],[1,2]]All three pairs of distinct indices are valid: [0,1], [0,2] and [1,2].
Constraints
0 <= durations.length <= 601 <= durations[i] <= 1000000