Dsa
Prefix Sum
Easy
Rhythmic Divisibility
In music theory, a 'Rhythmic Phrase' is a contiguous sequence of beat intensities. Given an array of N intensities and a rhythm factor T, a phrase is 'Perfect' if the sum of its intensities is perfectly divisible by T. Count the total number of Perfect phrases in the sequence.
Example:
Input:
4 3
1 2 3 1
Output:
4
Explanation:
Phrases: [1,2] (sum 3), [3] (sum 3), [1,2,3] (sum 6), [2,3,1] (sum 6). All sums are divisible by 3.
Key concepts
prefix_summodular_arithmetic
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now