Problem statement

https://binarysearch.com/problems/Sort-by-Permutation/

Solution

Just create dictionary and then traverse it.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, lst, p):
        d = {x:y for x, y in zip(p, lst)}
        return [d[i] for i in range(len(d))]