You are given an integer array nums and an integer k.
You may repeatedly choose any contiguous subarray of nums whose sum is divisible by k and delete it; after each deletion, the remaining elements close the gap.
Return the minimum possible sum of nums after performing any number of such deletions.
Example 1:
Input: nums = [1,1,1], k = 2
Output: 1
Explanation:
nums[0..1] = [1, 1], whose sum is 2 (divisible by 2), leaving [1].Example 2:
Input: nums = [3,1,4,1,5], k = 3
Output: 5
Explanation:
nums[1..3] = [1, 4, 1], whose sum is 6 (divisible by 3), leaving [3, 5].nums[0..0] = [3], whose sum is 3 (divisible by 3), leaving [5].Constraints:
1 <= nums.length <= 1051 <= nums[i] <= 1061 <= k <= 105k precisely when the prefix sums at its two endpoints have the same remainder mod k.dp[i] as the minimum total remaining sum after processing the first i elements.dp[j] - prefixSum[j] you've seen for that remainder to update dp[i] in O(1).[1,1,1] 2
[3,1,4,1,5] 3