# SkillUpper

but it's hard to get a detailed understanding that way

and then you can work on next steps

We would like to write a function that traverses a square matrix in a spiral. The spiral would go from outside to inside, and would go in clockwise order.

For example, given this input:

ABCD

EFGH

IJKL

MNOP

`var = [["A","B","C","D"],["E","F","G","H"],["I","J","K","L"],["M","N","O","P"]]; = [["A","B","C","D"],["E","F","G","H"],["I","J","K","L"],["M","N","O","P"]]`

The output of the function would be:

["A","B","C","D","H","L","P","O","N","M","I","E","F","G","K","J"]

However, let's take this step by step. First, let's write a function called ` that would traverse the outer layer of the matrix.`

For this input:

ABCD

EFGH

IJKL

MNOP

`var = [["A","B","C","D"],["E","F","G","H"],["I","J","K","L"],["M","N","O","P"]]; = [["A","B","C","D"],["E","F","G","H"],["I","J","K","L"],["M","N","O","P"]]`

The output of the function would be:

["A","B","C","D","H","L","P","O","N","M","I","E"]

This can be implemented with 4 loops for the 4 edges of the matrix to traverse.

Log In

Other tutorials:

N Queens - Recursive Backtracking

Fibonacci - Dynamic Programming

Basketball Scores - Dynamic Programming