Sort by

recency

|

1548 Discussions

|

  • + 0 comments

    I totally agree! When I had just read the problem, I thought that I probably could get it in one line of code. Focusing on reducing equipment failure as a mindset, I broke the entire problem into just a few steps and was able to get a solution that only took one line of code!

  • + 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;
    }