Tap here to switch tabs
Problem
Submissions

Problem: Find the Minimum Cost Array Permutation

med
30 min
Try to solve the Find the Minimum Cost Array Permutation problem.

Statement

Given an integer array nums of length n, which is a permutation of [0,1,…,n−1][0, 1, \dots, n - 1].

For any permutation perm of [0,1,…,n−1][0, 1, \dots, n - 1], its score is defined as:

$ ext{score}(perm) = \sum_{i = 0}^{n - 1} |perm[i] - nums[perm[(i + 1) \bmod n]}|$

Return the permutation perm that achieves the minimum score. If multiple permutations achieve the minimum score, return the lexicographically smallest permutation among them.

Constraints:

  • 2≤n=2 \leq n = nums.length ≤14\leq 14

  • nums is a permutation of [0,1,2,…,n−1][0, 1, 2, \dots, n - 1].

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Minimum Cost Array Permutation

med
30 min
Try to solve the Find the Minimum Cost Array Permutation problem.

Statement

Given an integer array nums of length n, which is a permutation of [0,1,…,n−1][0, 1, \dots, n - 1].

For any permutation perm of [0,1,…,n−1][0, 1, \dots, n - 1], its score is defined as:

$ ext{score}(perm) = \sum_{i = 0}^{n - 1} |perm[i] - nums[perm[(i + 1) \bmod n]}|$

Return the permutation perm that achieves the minimum score. If multiple permutations achieve the minimum score, return the lexicographically smallest permutation among them.

Constraints:

  • 2≤n=2 \leq n = nums.length ≤14\leq 14

  • nums is a permutation of [0,1,2,…,n−1][0, 1, 2, \dots, n - 1].