vcb37253
Search for a command to run...
You are given an integer array nums of size N and an integer k.
You need to split the array into one or more contiguous subarrays. For each subarray:
Cost of a subarray = k + number of duplicate elements in that subarray
Duplicate counting rule:
First occurrence is not counted
Every additional occurrence of the same number is counted as a duplicate
Your task is to return the minimum total cost after splitting the array optimally.
Input Format
Single line input:
[nums], k
Example:
[1,2,1,2,1,3,3], 2
Output Format
Return a single integer:
Minimum total cost
Constraints
1 ≤ N ≤ 1000
0 ≤ nums[i] ≤ 1000
1 ≤ k ≤ 1000
Expected Time Complexity: O(N²)
Expected Space Complexity: O(N)
Example 1
[1, 1, 1, 1], 10
13
Example 2
[1, 2, 1, 2, 1, 3, 3], 2
8
Example 3
[4, 4, 4], 1
3