Last active
March 29, 2023 09:17
-
-
Save danielhaim1/8994e1810cb06b60c40c597e8a195fa8 to your computer and use it in GitHub Desktop.
Inverse Permutation Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function inversePermutation(permutation) { | |
const n = permutation.length; | |
const result = Array(n); | |
for (let i = 0; i < n; i++) { | |
result[permutation[i] - 1] = i + 1; | |
} | |
return result; | |
} | |
// const permutation = [3, 1, 4, 5, 2]; | |
// const inverse = inversePermutation(permutation); | |
// console.log(inverse); // [2, 1, 5, 3, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment