You're managing a music streaming service and need to create perfect playlist pairs for your users. Given an array of song durations (in seconds), you need to find all pairs of songs where the combined duration is divisible by 60 seconds (i.e., forms a complete minute multiple).
More formally, given an array time where time[i] represents the duration of the i-th song in seconds, return the number of pairs (i, j) where:
i < j(to avoid counting the same pair twice)(time[i] + time[j]) % 60 == 0(sum is divisible by 60)
Example: If you have songs with durations [30, 20, 150, 100, 40], the pairs (30, 150) and (20, 100) both sum to 180 seconds (3 minutes), and (20, 40) sums to 60 seconds (1 minute).
Input & Output
Visualization
Time & Space Complexity
Single pass through the array with constant time operations
Fixed-size array of 60 elements regardless of input size
Constraints
- 1 โค time.length โค 6 ร 104
- 1 โค time[i] โค 500
- Follow-up: Can you solve it in O(n) time?