Software Engineering And Web Development: Make Sum Divisible By P
Remove smallest subarray to make sum divisible by p: use prefix sums & hash table for efficient search
1590. Make Sum Divisible by P Difficulty: Medium Topics: Array, Hash Table, Prefix Sum Given an array of positive integers nums, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible by p. It is not allowed to remove the whole array. Return the length of the smallest subarray that you need to remove, or -1 if it's impossible. A subarray is defined as a contiguous block of elements in the array. Example 1: Input: nums = [3,1,4,2], p = 6 Output: 1 Explanation: The sum of the elements in nums is 10, which is not divisible by 6. We can remove the s...