Pairs of Songs With Total Durations Divisible by 60
Real-world version: Pairs of Tracks Filling Whole MinutesThe 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.
def num_pairs_divisible_by60(seconds: list[int]) -> int:public int numPairsDivisibleBy60(int[] seconds)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's