Not sure why Time Limit Exceeded error is coming!

programming
Tags: #<Tag:0x00007f24289cd508>

#1

Not sure why Time Limit Exceeded error is coming for this solution, as the time complexity for the code I submitted will be O(n) !!

Can some one help me to understand, why this is happening ?

generateMatrix : function(A){
    var array = [];
    var max = A*A;
    for(var x=0, y=A, value=0; value<max ; x++, y--){
        var i = j = x;
        for(; j<y; j++){
            array[i] = array[i] || [];
            array[i][j] = ++value;
        }
        for(++i, --j; i<y; i++){
            array[i] = array[i] || [];
            array[i][j] = ++value;
        }
        for(--i, --j; j>=x; j--){
            array[i][j] = ++value;
        }
        for(--i, ++j; i>x; i--){
            array[i][j] = ++value;
        }
    }
    return array;
}