FPEvalDataset/LeetCodeProblem
0302
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 00:00:00",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 "public_test_cases": [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 "private_test_cases": [21 {22 "input": [23 3,24 1,25 2,26 027 ],28 "output": [29 0,30 1,31 2,32 333 ]34 },35 {36 "input": [37 1,38 5,39 6,40 0,41 2,42 4,43 344 ],45 "output": [46 0,47 3,48 6,49 2,50 4,51 5,52 153 ]54 },55 {56 "input": [57 2,58 4,59 6,60 1,61 7,62 3,63 0,64 8,65 566 ],67 "output": [68 0,69 3,70 5,71 8,72 7,73 4,74 1,75 6,76 277 ]78 },79 {80 "input": [81 0,82 7,83 1,84 8,85 5,86 10,87 9,88 6,89 4,90 3,91 292 ],93 "output": [94 0,95 2,96 10,97 5,98 4,99 8,100 3,101 9,102 6,103 7,104 1105 ]106 },107 {108 "input": [109 2,110 0,111 1112 ],113 "output": [114 0,115 1,116 2117 ]118 },119 {120 "input": [121 4,122 3,123 1,124 6,125 5,126 0,127 2128 ],129 "output": [130 0,131 2,132 6,133 3,134 1,135 5,136 4137 ]138 },139 {140 "input": [141 0,142 5,143 6,144 4,145 7,146 3,147 1,148 9,149 2,150 8151 ],152 "output": [153 0,154 6,155 2,156 8,157 9,158 7,159 4,160 3,161 5,162 1163 ]164 },165 {166 "input": [167 13,168 0,169 9,170 1,171 3,172 4,173 2,174 12,175 6,176 10,177 11,178 8,179 5,180 7181 ],182 "output": [183 0,184 1,185 3,186 4,187 5,188 8,189 11,190 10,191 9,192 2,193 6,194 12,195 7,196 13197 ]198 },199 {200 "input": [201 0,202 1203 ],204 "output": [205 0,206 1207 ]208 },209 {210 "input": [211 1,212 2,213 0214 ],215 "output": [216 0,217 2,218 1219 ]220 }221 ],222 "haskell_template": "findPermutation :: [Int] -> [Int]\nfindPermutation nums ",223 "ocaml_template": "let findPermutation (nums: int list) : int list = ",224 "scala_template": "def findPermutation(nums: List[Int]): List[Int] = { \n \n}",225 "java_template": "class Solution {\n public int[] findPermutation(int[] nums) {\n \n }\n}",226 "python_template": "class Solution(object):\n def findPermutation(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"\n "227}