Tap here to switch tabs
Problem
Submissions

Problem: Make K-Subarray Sums Equal

Try to solve the Make K-Subarray Sums Equal problem.

Statement

You are given a 00 indexed integer array arr and an integer k. The array is circular, which means the element immediately following the last element is arr[0], and the element immediately preceding arr[0] is the last element.

In a single operation, you can select any index i and increment or decrement arr[i] by 11.

Return the minimum number of operations required to make the sum of every contiguous subarray of length k equal.

Note: A subarray of length k starting at index i consists of the elements from arr[i] up to arr[(i + k - 1) % arr.length].

Constraints:

  • 1≤1 \leq k ≤\leq arr.length ≤105\leq 10^5

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

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Make K-Subarray Sums Equal

Try to solve the Make K-Subarray Sums Equal problem.

Statement

You are given a 00 indexed integer array arr and an integer k. The array is circular, which means the element immediately following the last element is arr[0], and the element immediately preceding arr[0] is the last element.

In a single operation, you can select any index i and increment or decrement arr[i] by 11.

Return the minimum number of operations required to make the sum of every contiguous subarray of length k equal.

Note: A subarray of length k starting at index i consists of the elements from arr[i] up to arr[(i + k - 1) % arr.length].

Constraints:

  • 1≤1 \leq k ≤\leq arr.length ≤105\leq 10^5

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