Given a 2D matrix, construct a linked list whose nodes follow the spiral order of the matrix (clockwise, starting at the top-left). Return the linked list as an array of values in spiral order. The matrix is given as a JSON array of rows.
Input: JSON array of rows (the matrix).
Output: Array — values in spiral order.
Input: [[1,2,3],[4,5,6],[7,8,9]]
Output: [1,2,3,6,9,8,7,4,5]
Explanation: Clockwise spiral.Input: [[1,2,3,4]]
Output: [1,2,3,4]
Explanation: Single row.Input: [[1],[2],[3]]
Output: [1,2,3]
Explanation: Single column.1<=rows,cols<=100