Skip to content

Latest commit

 

History

History
 
 

spiralmatrixgenerator

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Spiral matrix generator

Instructions

Given integer n implement a function which generates a spiral numbers matrix (size n x n). Numbers in matrix are placed according to spiral - starting top left corner and then go right, down, left, up, right...

Challenge | Solution

Examples

Example 1

generateSpiralMatrix(2)
   [[1, 2],
   [4, 3]]

Example 2

generateSpiralMatrix(3)
   [[1, 2, 3],
   [8, 9, 4],
   [7, 6, 5]]

Example 3

generateSpiralMatrix(4)
   [[1,   2,  3, 4],
   [12, 13, 14, 5],
   [11, 16, 15, 6],
   [10,  9,  8, 7]]