Skip to content
BytePatterns

Song Pairs Filling Whole Minutes

MediumMath & Number Theory#modular-arithmetic#remainder-count~20m

Problem

You are given the lengths of songs in seconds. Count the pairs of songs, at positions i < j, whose total length is a whole number of minutes, meaning the sum of the two lengths is divisible by 60.

Examples

Input:  times = [30, 20, 150, 100, 40]
Output: 3
Why:    30 + 150, 20 + 100 and 20 + 40 are 180, 120 and 60 seconds
Input:  times = [60, 60, 60]
Output: 3
Why:    every pair of the three songs adds up to 120 seconds
Input:  times = [10, 20]
Output: 0
Why:    edge case, 30 seconds is not a whole minute

Hints

0 / 3

Stuck on the idea rather than the code? Modular Arithmetic covers it.