#Spiral Array

1 messages ยท Page 1 of 1 (latest)

uncut crowBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

int minRow = 0;

    int maxRow = n-1;
    
    while (c <= n*n) {
        for (int i = minCol; i <= maxCol; i++) {
            sp[minRow][i] = c++;
        }
        
        for (int i = minRow+1; i <= maxRow; i++) {
            sp[i][maxCol] = c++;
        }
        
        for (int i = maxCol-1; i >= minCol; i--) {
            sp[maxRow][i] = c++;
        }
        
        for (int i = maxRow-1; i >= minRow+1; i--) {
            sp[i][minCol] = c++;
        }
        
        minCol++;
        
        minRow++;
        
        maxCol--;
        
        maxRow--;
    }
    
    return sp;
}```