hardArrayDynamic ProgrammingHash TableHeap Priority QueueMathSliding Window 0 views

Minimum Operations to Make Elements Within K Subarrays Equal

You are given an integer array nums and two integers, x and k.

You are given an integer array nums and two integers, x and k. You can perform the following operation any number of times (including zero):

Return the minimum number of operations needed to have at least k non-overlapping subarrays of size exactly x in nums, where all elements within each subarray are equal.

Minimum Operations to Make Elements Within K Subarrays Equal diagram

Example 1

Input: nums = [5,-2,1,3,7,3,6,4,-1], x = 3, k = 2

Output: 8

Example 2

Input: nums = [9,-2,-2,-2,1,5], x = 2, k = 2

Output: 3

Constraints

  • 2 <= nums.length <= 10^5
  • -10^6 <= nums[i] <= 10^6
  • 2 <= x <= nums.length
  • 1 <= k <= 15
  • 2 <= k * x <= nums.length

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.