Sort by

recency

|

1547 Discussions

|

  • + 0 comments

    **Mine Python Solution **

    def permutationEquation(p):
        # Write your code here
        a = [p.index(i)+1 for i in range(min(p),max(p)+1)]
        b = [p.index(i)+1 for i in a ]
    return b 
    
  • + 0 comments

    C++ solution

    vector<int> permutationEquation(vector<int> p)
    {
        vector<int> o(p.size());
        int j,k=0;
        for (int i = 1; i <= p.size(); ++i)
        {
            while (p[j] != i && j < p.size()) {++j;};
            while (p[k] != j+1 && k < p.size()) {++k;};
            
            o.at(i-1) = k+1;
            
            j = 0;
            k = 0;
        }
        
        return o;
    }
    
  • + 0 comments
    def permutationEquation(p):
        # Write your code here
        temp = {value: index + 1 for index, value in enumerate(p)}
        result = []
        for x in range(1, len(p)+1):
            i = temp.get(x)
            j = temp.get(i)
            result.append(j)
            
        return result
    
  • + 0 comments
    public static List<Integer> permutationEquation(List<Integer> p) {
        Map<Integer, Integer> map = IntStream.
                range(0, p.size()).
                boxed().
                collect(Collectors.toMap(s-> p.get(s), s-> s+1));
        List<Integer> result = IntStream.range(1, p.size()+1).
            boxed().
            map(map::get).
            map(map::get).
            collect(Collectors.toList());
        return result;
    }
    
  • + 0 comments

    Here's my easiest javascript solution :)

    let result=Array.from({ length: p.length });
        let positionVal;
        
        p.forEach((elem,index)=>{
            positionVal=(p.indexOf(index+1))+1;
            result[elem-1]=positionVal
        })
      
        return result;