Arrays: Left Rotation

  • + 0 comments
    int main(){
        int n; 
        int k; 
        int temp1, temp2;
        scanf("%d %d",&n,&k);
        
        int *a = malloc(sizeof(int) * n);
        for(int a_i = 0; a_i < n; a_i++){
           scanf("%d",&a[a_i]);
        }
        k = k %n;
        for(int a_i = 0; a_i < k; a_i++){
            temp1 = a[0];
            for(int i = 1; i < n; i++){
                a[i-1] = a[i];
            }
            a[n-1] = temp1;
        }
    
        for(int a_i = 0; a_i < n; a_i++){
           printf("%d ", a[a_i]);
        }
        
        return 0;
    }
    

    my code is the same as yours but i still time in test case 8, why is that?