As reported: Millennium Quantitative Developer (Python) round 2 (2025): one DSA problem — count the subarrays whose sum is divisible by a constant
K— followed by asyncio.
This is LeetCode 974 — Subarray Sums Divisible by K.
Given an integer array nums and an integer k, return the number of non-empty contiguous subarrays whose sum is divisible by k.
Example 1
nums = [4,5,0,-2,-3,1], k = 5
Output: 7
[4,5,0,-2,-3,1], [5], [5,0], [5,0,-2,-3], [0], [0,-2,-3], [-2,-3].
Example 2
nums = [5], k = 9
Output: 0
Constraints: 1 ≤ nums.length ≤ 3 · 10^4; -10^4 ≤ nums[i] ≤ 10^4; 2 ≤ k ≤ 10^4.
Code runner format: one JSON value per line: nums, then k. Implement subarraysDivByK(nums, k).