Hackerrank challenge timout : <p>hey i am just trying to solve a challenge on hackerrank but in some test cases the code timeouts and i don't know why. <a href="https://www.hackerrank.com/challenges/circular-array-rotation" rel="nofollow noreferrer">This is the challenge</a>.</p>

<p>And here is my code:</p>

<pre><code>#include &lt;math.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;assert.h&gt;
#include &lt;limits.h&gt;
#include &lt;stdbool.h&gt;

int main(){
    int n, k, q; 
    scanf("%d %d %d",&amp;n,&amp;k,&amp;q);
    int qs[q];
    int a[n];

    for(int i = 0; i &lt; n; i++){
       scanf("%d", &amp;a[i]);
    }


    for(int i = 0; i &lt; q; i++){
        scanf("%d",&amp;qs[i]);
    }

    int lastNbr = a[n-1];
    for(int i = 0; i &lt; k; i++){
        lastNbr = a[n-1];
        for(int j = n - 1; j &gt; -1; j--){
            a[j] = (j-1 &gt;= 0) ? a[j-1] : lastNbr;
        }
    }

    for(int i = 0; i &lt; q; i++){
        printf("%d\n", a[qs[i]]);
    }

    return 0;
}
</code></pre>
