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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Sequence Equation
  5. Discussions

Sequence Equation

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • josephlmyers
    4 months ago+ 0 comments

    It's nearly impossible to write a readable solution to such a nonsensical problem. It's bascially asking you to think in terms of POSITION instead of 0 based index. The solution to that problem is a 1 based index, hence the + 1's you see.

    Java 8 Solution:

    public static List<Integer> permutationEquation(List<Integer> intArray) {
        // Write your code here
        List<Integer> returnList = new ArrayList<Integer>();
        for(int i = 1; i <= intArray.size(); i++){
          int outterPos = intArray.indexOf(i) + 1;
          returnList.add(intArray.indexOf(outterPos) + 1);
        }
        return returnList;
    
      }
    
    
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy