top of page

Looking to master object-oriented and system design for tech interviews or career growth?

  • Improve your system design and machine coding skills.

  • Study with our helpful resources.

  • Prepare for technical interviews and advance your career.

**We're in beta mode and would love to hear your feedback.

Writer's pictureilluminati

Spiral Order Matrix II Interviewbit Solution


Problem Description:

Given an integer A, generate a square matrix filled with elements from 1 to A2 in spiral order.


Input Format:

The first and the only argument contains an integer, A. 

Output Format:

Return a 2-d matrix of size A x A satisfying the spiral order. 

Constraints:

1 <= A <= 1000 

Examples:

Input 1:
    A = 3

Output 1:
    [   [ 1, 2, 3 ],
        [ 8, 9, 4 ],
        [ 7, 6, 5 ]   
    ]
Input 2:
    4

Output 2:
    [   [1, 2, 3, 4],
        [12, 13, 14, 5],
        [11, 16, 15, 6],
        [10, 9, 8, 7]   
    ]

Solution:


Comentarios


bottom of page