FPEvalRepoPublic/LeetCodeMetaData
0399
1{2 "id": 3431,3 "name": "find-the-minimum-cost-array-permutation",4 "difficulty": "Hard",5 "link": "https://leetcode.com/problems/find-the-minimum-cost-array-permutation/",6 "date": "2024-05-05",7 "task_description": "You are given an array `nums` which is a permutation of `[0, 1, 2, ..., n - 1]`. The **score** of any permutation of `[0, 1, 2, ..., n - 1]` named `perm` is defined as: `score(perm) = |perm[0] - nums[perm[1]]| + |perm[1] - nums[perm[2]]| + ... + |perm[n - 1] - nums[perm[0]]|` Return the permutation `perm` which has the **minimum** possible score. If _multiple_ permutations exist with this score, return the one that is lexicographically smallest among them. **Example 1:** **Input:** nums = [1,0,2] **Output:** [0,1,2] **Explanation:** **** The lexicographically smallest permutation with minimum cost is `[0,1,2]`. The cost of this permutation is `|0 - 0| + |1 - 2| + |2 - 1| = 2`. **Example 2:** **Input:** nums = [0,2,1] **Output:** [0,2,1] **Explanation:** **** The lexicographically smallest permutation with minimum cost is `[0,2,1]`. The cost of this permutation is `|0 - 1| + |2 - 2| + |1 - 0| = 2`. **Constraints:** `2 <= n == nums.length <= 14` `nums` is a permutation of `[0, 1, 2, ..., n - 1]`.",8 "test_case": [9 {10 "label": "Example 1",11 "input": "nums = [1,0,2]",12 "output": "[0,1,2] "13 },14 {15 "label": "Example 2",16 "input": "nums = [0,2,1]",17 "output": "[0,2,1] "18 }19 ],20 "constraints": [21 "2 <= n == nums.length <= 14",22 "nums is a permutation of [0, 1, 2, ..., n - 1]."23 ],24 "python_template": "class Solution(object):\n def findPermutation(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"\n ",25 "java_template": "class Solution {\n public int[] findPermutation(int[] nums) {\n \n }\n}",26 "metadata": {27 "func_name": "findPermutation"28 }29}