Editor

Songs That End on the Minute

#625 · Dictionaries and sets · Intermediate · Fast enough · 75 XP · about 15 min

A radio host likes to play two songs back to back so that together they last a whole number of minutes. durations lists the length of every song in the library, in seconds.

Write whole_minute_pairs(durations) that returns how many pairs of songs have a total length that is a multiple of 60 seconds. A pair is two different positions in the list, counted once, so two songs of the same length still make a pair.

Examples

whole_minute_pairs([30, 20, 150, 100, 40])  # returns 3
whole_minute_pairs([60, 60, 60])            # returns 3
whole_minute_pairs([45, 50])                # returns 0

In the first example the pairs are 30 + 150 = 180, 20 + 100 = 120 and 20 + 40 = 60 seconds.

Constraints

  • 0 <= len(durations) <= 200,000
  • 1 <= durations[i] <= 1,000

Time limit

Each test must finish within 10 seconds, and the hidden tests have libraries of 200,000 songs.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.