• + 1 comment

    I think there is wrong answer in test case n = 69660 and k = 1620 this shouldn't be -1, why test case #12 shows it -1 ?

    this my code in c

    int* absolutePermutation(int n, int k, int* result_count) {
        
        int * pos = calloc(n, sizeof(int)) , i = 0;
        
        if(k == 0)
        {
            for( i = 0 ; i<n ; i++)
            {
                pos[i] = i+1;   
            }
            *result_count = n;
        }
        else if( ( (n%2 == 0) && (n%k == 0) && (n != k)))
        {
            for(i = 0 ; i<n ; i++)
            {
                if ( (i/k)%2 == 0 ) {
                    pos[i] = (i+1+k);          
                }
                else
                {
                    pos[i] = (i+1-k);
                }
            }   
            
            *result_count = n;
        }
        else {
            pos = realloc(pos, sizeof(int));
            pos[0] = -1;
            * result_count = 1;
        }
        
        return pos;
    }