Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Split an Array

med
30 min
Try to solve the Minimum Cost to Split an Array problem.

Statement

You are given an integer array nums and an integer k.

You need to partition nums into one or more non empty contiguous subarrays. The cost of a partition is defined as the sum of the importance values of each subarray in the partition.

The importance value of a subarray is k+exttrimmed(extsubarray)ext.lengthk + ext{trimmed}( ext{subarray}) ext{.length}, where $ ext{trimmed}( ext{subarray})$ is obtained by removing all elements from the subarray that appear exactly once within it.

Return the minimum possible total cost to split nums.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 0≤0 \leq nums[i] << nums.length

  • 1≤1 \leq k ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Split an Array

med
30 min
Try to solve the Minimum Cost to Split an Array problem.

Statement

You are given an integer array nums and an integer k.

You need to partition nums into one or more non empty contiguous subarrays. The cost of a partition is defined as the sum of the importance values of each subarray in the partition.

The importance value of a subarray is k+exttrimmed(extsubarray)ext.lengthk + ext{trimmed}( ext{subarray}) ext{.length}, where $ ext{trimmed}( ext{subarray})$ is obtained by removing all elements from the subarray that appear exactly once within it.

Return the minimum possible total cost to split nums.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 0≤0 \leq nums[i] << nums.length

  • 1≤1 \leq k ≤109\leq 10^9