410. Round-Minute Pairs

A podcast app queues short clips whose lengths are given in seconds. The editor likes to chain exactly two clips so that the combined running time is a whole number of minutes, meaning it is divisible by 60 seconds.

Given the array durations, return the number of index pairs (i, j) with i < j for which durations[i] + durations[j] is divisible by 60. Pairs are counted by position, so equal lengths at different positions form different pairs. It is guaranteed that the answer fits in a signed 32-bit integer.

Example 1

Input:
durations = [25,35,60,120,45,15]
Output:
3
Explanation:

The qualifying position pairs are (25,35), (60,120) and (45,15), so the answer is 3.

Example 2

Input:
durations = [30,30,30]
Output:
3
Explanation:

Any two of the three 30-second clips total 60 seconds, giving 3 pairs.

Constraints

1 ≤ durations.length ≤ 2 * 105

1 ≤ durations[i] ≤ 109

The answer fits in a signed 32-bit integer.

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Time per case
Python 1,600 msC++ 400 msJava 800 msJavaScript 800 msTypeScript 800 ms

Expected complexity

Time
O(n)
Space
O(1)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…