Show problems as
Classic problem #1010MediumArrayHash TableCounting

Pairs of Songs With Total Durations Divisible by 60

Real-world version: Pairs of Tracks Filling Whole Minutes
Tracked in this browser only
Read Pairs of Songs With Total Durations Divisible by 60 on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A playlist's track lengths, in seconds, read seconds.

Return how many pairs of different positions hold two tracks whose lengths add up to a whole number of minutes, that is to a multiple of sixty seconds. A pair counts once, whichever order it is taken in.

Examples

Example 1

Input
seconds = [30, 30]
Output
1

The two lengths of thirty add to sixty, exactly one whole minute.

Example 2

Input
seconds = [59, 1, 120]
Output
1

Fifty-nine and one add to sixty. The track of a hundred and twenty already fills two whole minutes on its own, but a pair needs two tracks, and it leaves neither of the others on a whole minute.

Example 3

Input
seconds = [500, 500, 500, 500]
Output
0

Five hundred leaves twenty over a whole minute, and twenty and twenty come to forty, never sixty.

Constraints

  • 1 <= seconds.length <= 6 * 10^4
  • 1 <= seconds[i] <= 500

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def num_pairs_divisible_by60(seconds: list[int]) -> int:
Java
public int numPairsDivisibleBy60(int[] seconds)