Dsa
Prefix Sum
Medium
Continuous Subarray Sum
You are given an integer array nums and an integer k. Find the number of continuous subarrays that sum to a multiple of k. A subarray is defined as a contiguous part of an array. Your task is to implement a function that takes these inputs and returns the count of such subarrays.
Input Format:
- The first line contains an integer n (the length of the array).
- The second line contains n space-separated integers (the elements of the array nums).
- The third line contains an integer k (the target divisor).
Output Format:
- Output a single integer representing the count of continuous subarrays whose sum is a multiple of k.
Example:
Input:
5
1 2 3 4 5
3
Output:
4
Key concepts
prefix_sumsubarraycumulative_sum
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