• + 0 comments

    Java 100% O(N):

    public static List<Integer> permutationEquation(List<Integer> p) {
        List<Integer> y = new ArrayList<>();
        Map<Integer, Integer> idxToValue = new HashMap<>();
        for (int i=1 ; i<=p.size() ; i++) {
            idxToValue.put(p.get(i-1), i);
        }
    
        for (int i=1 ; i<=p.size() ; i++) {
            y.add(idxToValue.get(idxToValue.get(i)));
        }
    
        return y;
    }