Pairs of Songs With Total Durations Divisible by 60
A medium-tier problem at 53% community acceptance, tagged with Array, Hash Table, Counting. Reported in interviews at BlackRock and 8 others.
You're given an array of song durations in seconds and need to count pairs that sum to a multiple of 60. It sounds simple until you realize the brute force O(n^2) approach will timeout on large datasets. BlackRock, PayPal, Goldman Sachs, and TikTok have all asked this. The trick isn't obvious, and if you blank on the modulo math during your live assessment, StealthCoder surfaces the working solution in seconds while the proctor sees nothing.
Companies that ask "Pairs of Songs With Total Durations Divisible by 60"
Pairs of Songs With Total Durations Divisible by 60 is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe insight is that you don't need to check all pairs. If a song has duration d, you only care about songs whose duration is (60 - d % 60) % 60 mod 60. Use a hash table to count occurrences of each modulo remainder, then iterate through and match complementary remainders. Watch the edge case: when remainder is 0 or 30, you're pairing songs with themselves, so use the combination formula n*(n-1)/2. Most candidates jump straight to nested loops or miss the modulo reduction entirely. Array iteration plus hash table lookup gives you O(n) time and O(1) space (max 60 buckets). If this pattern doesn't click during your assessment, StealthCoder runs invisibly and hands you the code.
Pattern tags
You know the problem.
Make sure you actually pass it.
Pairs of Songs With Total Durations Divisible by 60 recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Pairs of Songs With Total Durations Divisible by 60 interview FAQ
Why does modulo 60 matter here?+
Two durations sum to a multiple of 60 if (d1 + d2) % 60 == 0. This means d1 % 60 and d2 % 60 must sum to 0 or 60. Modulo collapses the problem from unbounded durations to just 60 possible remainders, making hash table lookup O(1).
Is this really asked at PayPal and Goldman Sachs?+
Yes. Nine major companies have reported it, including BlackRock, PayPal, Salesforce, and Goldman Sachs. Acceptance rate sits at 53%, which means half the candidates who attempt it get it wrong. The modulo trick isn't intuitive.
What's the gotcha with remainder 0 and 30?+
If two songs both have remainder 0 (duration divisible by 60), you can't pair one song with itself. Same for remainder 30 (duration % 60 == 30). Use combinations: for n songs with the same remainder, valid pairs = n*(n-1)/2, not n*n.
Can I just use a nested loop?+
No. O(n^2) will timeout on large arrays. Hash table approach is O(n) with one pass to count remainders, then one pass to pair them up. The difference between timeout and acceptance is this single insight.
How does this relate to the Array and Hash Table topics?+
You iterate the input array once (Array topic) and store remainder counts in a hash table (Hash Table topic). The Counting topic means you're tallying occurrences, not just checking existence. It's a clean example of all three working together.
Want the actual problem statement? View "Pairs of Songs With Total Durations Divisible by 60" on LeetCode →