• + 0 comments

    TS solution O(n):

    function permutationEquation(p: number[]): number[] {
        // Write your code here
        
        let map: {[key: number]: number} = {}
        
        for(let i = 0; i < p.length; i++) {
            map[p[i]] = i + 1
        }
        
        let result: number[] = []
        
        for(let i = 1; i <= p.length; i++) {
            let pypy: number = map[map[i]]
            result.push(pypy)
        }
        
        return result
    }