Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Achieve At Least K Peaks

Try to solve the Minimum Operations to Achieve At Least K Peaks problem.

Statement

You are given a circular integer array nums of length n and an integer k.

An element nums[i] is considered a peak if it is strictly greater than both of its adjacent neighbors, nums[(i - 1 + n) % n] and nums[(i + 1) % n].

In one operation, you can choose any index i and increment nums[i] by 11.

Return the minimum total number of operations required to make the array contain at least k peaks. If it is impossible to have at least k peaks, return −1-1.

Constraints:

  • 2≤n==2 \leq n == nums.length ≤5000\leq 5000

  • −105≤-10^5 \leq nums[i] ≤105\leq 10^5

  • 0≤k≤n0 \leq k \leq n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Achieve At Least K Peaks

Try to solve the Minimum Operations to Achieve At Least K Peaks problem.

Statement

You are given a circular integer array nums of length n and an integer k.

An element nums[i] is considered a peak if it is strictly greater than both of its adjacent neighbors, nums[(i - 1 + n) % n] and nums[(i + 1) % n].

In one operation, you can choose any index i and increment nums[i] by 11.

Return the minimum total number of operations required to make the array contain at least k peaks. If it is impossible to have at least k peaks, return −1-1.

Constraints:

  • 2≤n==2 \leq n == nums.length ≤5000\leq 5000

  • −105≤-10^5 \leq nums[i] ≤105\leq 10^5

  • 0≤k≤n0 \leq k \leq n