Subarray Sums Divisible by K Problem
Subarray Sums Divisible by K Problem — ExecCode Medium DSA Practice
Solve the Subarray Sums Divisible by K problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given an integer array nums and an integer k, return the count of contiguous non-empty subarrays whose sum is divisible by k.
Examples
Input nums = [4, 5, 0, -2, -3, 1], k = 5; Output 7. Input nums = [5], k = 9; Output 0. Input nums = [2, 2, 2, 2, 2], k = 4; Output 6
Constraints
1 ≤ nums.length ≤ 3×10⁴ -10⁴ ≤ nums[i] ≤ 10⁴ 2 ≤ k ≤ 10⁴
Practice Subarray Sums Divisible by K free on ExecCode. Browse DSA problems, topic map, and placement guides.