Count Pairs of Songs Whose Combined Length Fills Whole Minutes
Last updated: November 29, 2026
Quick Overview
Given the durations in seconds of songs in a YouTube Music playlist, count the pairs (i, j) with i < j whose total duration is a multiple of 60 seconds.
0
0
0 solved
Given the durations in seconds of songs in a YouTube Music playlist, count the pairs (i, j) with i < j whose total duration is a multiple of 60 seconds.
Typical of the short counting problems in Google's online assessment, themed on YouTube Music crossfade planning. The interviewer or grader checks that you reduce to remainders mod 60 and count complements in one pass, handling the special remainders 0 and 30.
What the Interviewer Expects
- Reduces each duration modulo 60
- Counts complement remainders seen so far in one pass
- Handles remainder 0 and remainder 30 correctly
- Avoids double counting pairs
- Achieves O(n) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Generalize to any modulus k; what changes?
- Count triples whose total is a multiple of 60.
- How would you return the actual pairs if there are few of them?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list of positive integers
durations. - Output: number of index pairs
i < jwith(durations[i] + durations[j]) % 60 == 0. - n can be large (up to 10^5 or more), so O(n^2) is too slow....
High-Level Design
Only the remainder modulo 60 matters. A song with remainder r pairs with any earlier song whose remainder is (60 - r) % 60. The % 60 on the complement maps remainder 0 to itself, and remainder 3...