Question bank › Prefix Sum
Dsa Prefix Sum Medium

Sum of Subarrays Divisible by k

You are given an integer array nums and an integer k. Your task is to find the total number of continuous subarrays whose sum is divisible by k. Implement a function that reads the input and calculates the result. 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 divisor). Output Format: - Output a single integer representing the count of continuous subarrays whose sum is divisible by k. Example: Input: 5 4 5 0 -2 -3 1 5 Output: 7

Key concepts

prefix_sumdivisibilitysubarrays

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.