Testing every subarray costs O(n squared). Prefix sums with a remainder-frequency map solve it in a single O(n) pass: two prefixes sharing a remainder mod k enclose a divisible subarray. The pitfall is negative remainders. Here is the clean answer.
Unlock the other 847 answers · ₹2,000 / $25Your progress and mastery stay saved · 6 months · one payment · no auto-renew
