mediumArrays & HashingIndian domain~20 min
UPI Settlement Window Summing to a Multiple
A UPI settlement engine batches consecutive transaction amounts. A batch can be cleared only if it contains at least two transactions whose total is an exact multiple of the settlement unit k (in paise).
Problem
Given an integer array nums of transaction amounts and an integer k, return true if there exists a contiguous subarray of length at least 2 whose sum is a multiple of k (that is, sum mod k == 0). Treat 0 as a multiple of every k.
Input
An integer array nums and an integer k.
Output
A boolean: true if such a subarray exists, else false.
Constraints
- 1 <= nums.length <= 100000
- 0 <= nums[i] <= 10^9
- 1 <= k <= 2^31 - 1
Examples
Example 1
Input
nums = [23,2,4,6,7], k = 6
Output
true
[2,4] sums to 6, a multiple of 6.
Example 2
Input
nums = [23,2,6,4,7], k = 13
Output
false
No contiguous block of length >= 2 sums to a multiple of 13.