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.
divisible_pairs(durations: list[int], k: int) → int[[30,20,150,100,40],60]out3State 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.