Sort by

recency

|

1532 Discussions

|

  • + 0 comments

    Java

    public static List<Integer> permutationEquation(List<Integer> p) {
            List<Integer> result = new ArrayList<>();
            
            for (int x = 1; x <= p.size(); x++) {
                int px = p.indexOf(x) + 1;
                int py = p.indexOf(px) + 1;
                
                result.add(py);
            }
    
            return result;
        }
    
  • + 1 comment

    Here is my O(N) c++ solution, you can watch the explanation here : https://youtu.be/D9nfVOmmv7Q

    vector<int> permutationEquation(vector<int> p) {
        vector<int> indexes(p.size() + 1), result;
        for(int i = 1; i <= p.size(); i++) indexes[p[i-1]] = i;
        for(int i = 1; i <= p.size(); i++) result.push_back(indexes[indexes[i]]);
        return result;
    }
    
  • + 0 comments

    Here is my one line Python solution!

    def permutationEquation(p):
        return [p.index(p.index(i + 1) + 1) + 1 for i in range(len(p))]
    
  • + 1 comment

    The Sequence Equation can be tricky, but once you break it down step by step, it starts making sense! It's kind of like how Concrete Estimating Services work — you need accuracy and attention to detail. If you're looking for an easier way, using capcut for pc tools can really simplify the process and save time.

  • + 0 comments

    Python Method : Create dict to store the element as key and the index+1 of p as value. For example, [5,2,1,3,4] we can get {5:1, 2:2, 1:3, 3:4, 4:5} and use p_dict[p_dict[1]] to get the answer 4 . It can reduce the computing of list.index().

    def permutationEquation(p):
        p_dict = {j:i+1 for i,j in enumerate(p)}
        y = []
        for x in range(1,len(p)+1):
            y.append(p_dict[p_dict[x]])
        return y