+ 1

how to traverse the spiral traverse matrix to its original form.

function spiralTraversalIV(N, arr){ let left=0; let right=N-1; let top=0; let bottom=N-1; let count=0; let s=""; while(count < N*N){ for(let i=bottom;i>=top;i--){ s+=(arr[i][right])+" "; count++; } right--; for(let i=right;i>=left;i--){ s+=(arr[top][i])+" "; count++; } top++; for(let i=top;i<=bottom;i++){ s+=(arr[i][left])+" "; count++; } left++; for(let i=left;i<=right;i++){ s+=(arr[bottom][i])+" "; count++; } bottom--; } console.log(s); } spiralTraversalIV(3,[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]) out put 9 6 3 2 1 4 7 8 5 https://code.sololearn.com/cNF0nyRhHQy6 how can make my original string from my out-put?

30th Jun 2022, 10:25 AM
TINKLE DASH
TINKLE DASH - avatar
3 Answers
+ 1
Steve yes ,but I already solved this
10th Jul 2022, 8:06 PM
TINKLE DASH
TINKLE DASH - avatar
+ 1
TINKLE DASH Glad to hear it!
10th Jul 2022, 8:16 PM
Steve
Steve - avatar
0
Are you asking how to generate [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] from 9 6 3 2 1 4 7 8 5?
10th Jul 2022, 7:47 PM
Steve
Steve - avatar