Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes399downloads
minimum-cost-to-split-an-array.json37 linesDownload Raw Back to root
1{2  "id": 2633,3  "name": "minimum-cost-to-split-an-array",4  "difficulty": "Hard",5  "link": "https://leetcode.com/problems/minimum-cost-to-split-an-array/",6  "date": "2023-01-15",7  "task_description": "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. For example, `trimmed([3,1,2,4,3,4]) = [3,4,3,4].` The **importance value** of a subarray is `k + trimmed(subarray).length`. For example, if a subarray is `[1,2,3,3,3,4,4]`, then trimmed(`[1,2,3,3,3,4,4]) = [3,3,3,4,4].`The importance value of this subarray will be `k + 5`. Return _the minimum possible cost of a split of _`nums`. A **subarray** is a contiguous **non-empty** sequence of elements within an array. **Example 1:** ``` **Input:** nums = [1,2,1,2,1,3,3], k = 2 **Output:** 8 **Explanation:** We split nums to have two subarrays: [1,2], [1,2,1,3,3]. The importance value of [1,2] is 2 + (0) = 2. The importance value of [1,2,1,3,3] is 2 + (2 + 2) = 6. The cost of the split is 2 + 6 = 8. It can be shown that this is the minimum possible cost among all the possible splits. ``` **Example 2:** ``` **Input:** nums = [1,2,1,2,1], k = 2 **Output:** 6 **Explanation:** We split nums to have two subarrays: [1,2], [1,2,1]. The importance value of [1,2] is 2 + (0) = 2. The importance value of [1,2,1] is 2 + (2) = 4. The cost of the split is 2 + 4 = 6. It can be shown that this is the minimum possible cost among all the possible splits. ``` **Example 3:** ``` **Input:** nums = [1,2,1,2,1], k = 5 **Output:** 10 **Explanation:** We split nums to have one subarray: [1,2,1,2,1]. The importance value of [1,2,1,2,1] is 5 + (3 + 2) = 10. The cost of the split is 10. It can be shown that this is the minimum possible cost among all the possible splits. ``` **Constraints:** `1 <= nums.length <= 1000` `0 <= nums[i] < nums.length` `1 <= k <= 109`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "nums = [1,2,1,2,1,3,3], k = 2",12      "output": "8 "13    },14    {15      "label": "Example 2",16      "input": "nums = [1,2,1,2,1], k = 2",17      "output": "6 "18    },19    {20      "label": "Example 3",21      "input": "nums = [1,2,1,2,1], k = 5",22      "output": "10 "23    }24  ],25  "constraints": [26    "For example, trimmed([3,1,2,4,3,4]) = [3,4,3,4].",27    "For example, if a subarray is [1,2,3,3,3,4,4], then trimmed([1,2,3,3,3,4,4]) = [3,3,3,4,4].The importance value of this subarray will be k + 5.",28    "1 <= nums.length <= 1000",29    "0 <= nums[i] < nums.length",30    "1 <= k <= 109"31  ],32  "python_template": "class Solution(object):\n    def minCost(self, nums, k):\n        \"\"\"\n        :type nums: List[int]\n        :type k: int\n        :rtype: int\n        \"\"\"\n        ",33  "java_template": "class Solution {\n    public int minCost(int[] nums, int k) {\n        \n    }\n}",34  "metadata": {35    "func_name": "minCost"36  }37}