Tap here to switch tabs
Problem
Submissions

Problem: Make Sum Divisible by P

med
30 min
Try to solve the Make Sum Divisible by P problem.

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:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq p ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Make Sum Divisible by P

med
30 min
Try to solve the Make Sum Divisible by P problem.

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:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq p ≤109\leq 10^9