Sort by

recency

|

1540 Discussions

|

  • + 0 comments

    Java 100% O(N):

    public static List<Integer> permutationEquation(List<Integer> p) {
        List<Integer> y = new ArrayList<>();
        Map<Integer, Integer> idxToValue = new HashMap<>();
        for (int i=1 ; i<=p.size() ; i++) {
            idxToValue.put(p.get(i-1), i);
        }
    
        for (int i=1 ; i<=p.size() ; i++) {
            y.add(idxToValue.get(idxToValue.get(i)));
        }
    
        return y;
    }
    
  • + 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

    My python3 solution

    l = len(p)
    r = []
    for x in range(0,l):
        r.append( p.index ( (p.index(x+1))+1 ) + 1)
     return(r)
    
  • + 0 comments

    Kotlin:

    fun permutationEquation(p: Array<Int>): Array<Int> {
        val size=p.size
        val indexArray=IntArray(size) { 0 }
        val result=Array(size) { 0 }
        for(i in 0 until size){
            indexArray[i]= p.indexOf(i+1)+1
        }
        for(i in 0 until size){
            result[i]=p.indexOf(indexArray[i])+1
        }
        return result
    }
    
  • + 0 comments

    The Sequence Equation can be a bit tricky at first, but once you understand the pattern, it’s pretty satisfying to solve! It’s all about mapping numbers in a sequence and finding their positions. By the way, if you're looking for a stylish yet comfy choice, Women's Black Sandals are always a great go-to for any outfit! Perfect for casual days or dressing up a bit.