Skip to main content

Pairs of Songs With Total Durations Divisible by 60

MediumPremium

You're given a list of song lengths in seconds, time. Return how many pairs of songs have a total length that's divisible by 60. A pair is two different songs at indexes i < j.

Example 1

Input: time = [30, 20, 150, 100, 40] Output: 3

The pairs are 30 + 150 = 180, 20 + 100 = 120 and 20 + 40 = 60.

Example 2

Input: time = [60, 60, 60] Output: 3

Every pair adds up to 120, and three songs make three pairs.

Constraints

  • 1 <= time.length <= 60000
  • 1 <= time[i] <= 500