Search⌘ K
AI Features

Solution: Make Sum Divisible by P

C# solution for the Make Sum Divisible by P problem using the Hash Maps pattern.

Statement

Given an integer array nums and an integer p, you may remove exactly one contiguous subarray from nums (possibly removing nothing). After the removal, the remaining elements keep their original order.

Return the minimum possible length of a subarray that can be removed so that the sum of the remaining elements is divisible by p. If it is impossible to achieve divisibility without removing the entire array, return 1-1.

Note: Removing the entire array is not allowed.

Constraints:

  • 11 \leq nums.length ...