Pairs of Songs With Total Durations Divisible by 60 - Problem
You are given a list of songs where the i-th song has a duration of time[i] seconds.
Return the number of pairs of songs for which their total duration in seconds is divisible by 60.
Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0.
Input & Output
Example 1 — Basic Case
$
Input:
time = [30,20,150,100,40]
›
Output:
3
💡 Note:
Three pairs sum to multiples of 60: (30,150)=180, (20,40)=60, (100,40)=140. Wait, let me recalculate: (30,150)=180≡0, (20,40)=60≡0, (30,30) from positions would be invalid since we need i
Example 2 — Multiple Zeros
$
Input:
time = [60,60,60]
›
Output:
3
💡 Note:
All songs are 60 seconds (remainder 0). Every pair sums to 120≡0 (mod 60). Pairs: (0,1), (0,2), (1,2) = 3 pairs total.
Example 3 — No Valid Pairs
$
Input:
time = [10,50,90,30]
›
Output:
2
💡 Note:
Pairs that sum to multiples of 60: (10,50)=60 and (90,30)=120, so 2 pairs total.
Constraints
- 1 ≤ time.length ≤ 6 × 104
- 1 ≤ time[i] ≤ 500
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code