Skip to content

Practice Minimum Cost to Split an Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2547
LeetCode Problem

Minimum Cost to Split an Array

Problem Statement

You are given an integer array nums and an integer k. Split the array into some number of non-empty subarrays. The cost of a split is the sum of the importance value of each subarray in the split. Let trimmed(subarray) be the version of the subarray where all numbers which appear only once are removed. The importance value of a subarray is k + trimmed(subarray).length. Return the minimum possible cost of a split of nums. A subarray is a contiguous non-empty sequence of elements within an array.

Source: Minimum Cost to Split an Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,1,2,1,3,3], k = 2
Output
8

# Example 2

Input
nums = [1,2,1,2,1], k = 2
Output
6

# Example 3

Input
nums = [1,2,1,2,1], k = 5
Output
10

Constraints

1 <= nums.length <= 1000
0 <= nums[i] < nums.length
1 <= k <= 10^9

Related LeetCode Problems

Practice more problems similar to Minimum Cost to Split an Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.