#3149
Find the Minimum Cost Array Permutation
international master · 2095 · lc hard +32 · 25.4% accepted · 147 likes · top 4%
Description
Given an array nums that is a permutation of [0, 1, ..., n - 1], a permutation perm scores:score(perm) = |perm[0] - nums[perm[1]]| + |perm[1] - nums[perm[2]]| + ... + |perm[n - 1] - nums[perm[0]]|
Return the permutation with the minimum score. Break ties by choosing the lexicographically smallest one.
Code
1
2
3