For example a 3x3 grid.
[ 1 ] [ 2 ] [ 3 ]
[ 4 ] [ 5 ] [ 6 ]
[ 7 ] [ 8 ] [ 9 ]
I need traverse the the grid in a cyclical manner and output each number where the path has been.
The input for a 3x3 grid is a multidimensional array:
input = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
For a 3x3 grid the output should be an array or string.
output = [1, 2, 3, 6, 9, 8, 7, 4, 5]
The solution also needs to scale to any NxN grid.
I am looking for the solution of this programming problem. I have tried many different methods to do this but I can not seem to do it. I would love to learn how and also some bonus advice how I can improve my problem solving ability.