Sort by

recency

|

1530 Discussions

|

  • + 0 comments

    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

    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

    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
    
  • + 0 comments
    def permutationEquation(p):
        # Write your code here
        res = []
        for i in range(len(p)):
            x = p.index(i + 1)
            y = p.index(x + 1)
            res.append(y + 1)
        return res
    
  • + 0 comments

    Here is the solution of this question in PYTHON

    def permutationEquation(p):
        position1 = []
        position2 = []
        for i in range(1,len(p)+1):
            for j in range(len(p)):
                if(i == p[j]):
                    position1.append(j+1)
                    break
        for item in position1:
            for i in range(len(position1)):
                if(item == p[i]):
                    position2.append(i+1)
        return position2