Back to course home
0% completed
Vote For New Content
Pairs of Songs With Total Durations Divisible by 60 (medium)
Problem Statement
You are given a list of positive integer times
, where times[i]
represents the duration of i<sup>th</sup> song in seconds.
Return the number of unique song pairs
for which their total duration in seconds is multiple of 60
. In other words, find the number of indices i
, j
such that i < j
with (times[i] + times[j]) % 60 == 0
.
Examples
Example 1:
- Input: times =
[30, 20, 150, 100, 40, 110]
- Expected Output:
3
- Justification: The pairs of songs that can form a total duration divisible by 60 are (30, 150), (20, 100), and (20, 40). Each of these pairs sums up to a multiple of 60, hence the expected output is 3.
Example 2:
- Input: times =
[120, 180, 60]
- Expected Output:
3
- Justification: The sum of (120, 180), (120, 60), and (180, 60) are divisible by 60. So, the expected output is 3.
Example 3:
- Input: times =
[15, 225, 90, 60]
- Expected Output:
1
- Justification: The only pair of songs that can form a total duration divisible by 60 is (15, 225).
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible