Code Room
CodingMediumcod-g1248
Subject HashingLevel Entry–Mid~16 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A DJ tool suggests smooth crossfades between tracks whose combined duration lines up with a beat grid. Given a list of track durations in seconds and a grid length k (k >= 1), count the pairs of indices i < j such that durations[i] + durations[j] is divisible by k. For example, with durations [30, 20, 150, 100, 40] and k = 60, the qualifying pairs are (30, 150), (20, 100) and (20, 40), so the answer is 3. Checking every pair is O(n^2) — count by remainder instead.

Implement
divisible_pairs(durations: list[int], k: int) → int
Examples
in[[30,20,150,100,40],60]out3
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.