We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Sequence Equation
  5. Discussions

Sequence Equation

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 1314 Discussions, By:

recency

Please Login in order to post a comment

  • mallachandu99
    9 hours ago+ 0 comments
    function permutationEquation(p) {
    // Write your code here
    var map = new Map(),
       ar = [];
    
    
    p.forEach((v,i) => map.set(v, i+1))
    
    for(let i=1; i<=p.length; i++)
         ar.push( map.get ( map.get(i) ));
    
        return ar;
    
    0|
    Permalink
  • alban_tyrex
    3 days ago+ 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|
    Permalink
  • ujjwalgupta12721
    3 days ago+ 0 comments
    vector<int> permutationEquation(vector<int> p) {
    vector<int>ans;
    for(int i=1;i<=p.size();i++){
       int  it=find(p.begin(),p.end(),i)-p.begin();
        int iit=find(p.begin(),p.end(),it+1)-p.begin();
        ans.push_back(iit+1);
    }
        return ans;
    }
    
    0|
    Permalink
  • sabsfilho
    7 days ago+ 0 comments

    c# version

        public static List<int> permutationEquation(List<int> p)
        {
            var rs = new List<int>();
            for(int x = 1, n = p.Count; x <= n; x++)
            {
                int y = p.IndexOf(x) + 1;
                rs.Add(p.IndexOf(y) + 1);
            }
            return rs;
        }
    
    0|
    Permalink
  • devin1299
    1 week ago+ 0 comments

    pythnon:

    def permutationEquation(p):
        result = [0] * len(p)
        for i in range(len(p)):
            result[i] = p.index(p.index(i+1) + 1) + 1
        return result
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy