Efficient Cost
You will be given an integer array and a threshold value. The threshold represents the maximum length of subarrays that may be created for the challenge. Each subarray created has a cost equal to the maximum integer within the subarray. Partition the entire array into subarrays with lengths less than or equal to the threshold, and do it at a minimum cost. The subarrays are to be chosen from contiguous elements, and the given array must remain in its original order.
Complete the function efficientCost in the editor.
efficientCost has the following parameters:
- 1.
int[] arr: an integer array - 2.
int threshold: the maximum length of subarrays
Returns
int: the minimum cost to partition the array
1Example 1
Constraints
Limits and guarantees your solution can rely on.
Unknown for now.