Pairs of Songs With Total Durations Divisible by 60

MediumArrays & Hashinghashing

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

time[i] is the length of the i-th song in seconds. Count the index pairs (i, j) with i < j for which time[i] + time[j] is divisible by 60. Target O(n) time.

Examples

Input: time = [30,20,150,100,40]
Output: 3
The pairs are (30,150), (20,100) and (20,40), with totals 180, 120 and 60.
Input: time = [60,60,60]
Output: 3
Every pair sums to 120, and 3 songs form 3 pairs.

Constraints

  • 1 <= time.length <= 6 * 10^4
  • 1 <= time[i] <= 500

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More hashing problems