Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-153

Inverse Permutation of Indices

Problem

Given a permutation p of the indices 0 through n-1, return its inverse permutation q.

q is defined by q[p[i]] = i, so applying p and then q returns the identity order.

Hint

Swap the roles of index and value.

Test cases

case 1
in: [[0,1,2]]
expected: [0,1,2]
case 2
in: [[1,2,0]]
expected: [2,0,1]
case 3
in: [[2,0,1]]
expected: [1,2,0]
case 4
in: [[1,0]]
expected: [1,0]
Starter codePython
def inverse_permutation(p):
    # Your code here
    pass

4 test cases · run your code against them in the editor