Practice Find the Minimum Cost Array Permutation
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Find the Minimum Cost Array Permutation
Problem Statement
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.
Source: Find the Minimum Cost Array Permutation on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [1,0,2]
[0,1,2]
# Example 2
nums = [0,2,1]
[0,2,1]
Constraints
Related LeetCode Problems
Practice more problems similar to Find the Minimum Cost Array Permutation.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.