Broadridge Financial Solutions may represent statement or report data as a rectangular matrix. Given a matrix, return all values in clockwise spiral order, starting at the top-left corner.
Implement spiral_order(matrix), where matrix is a non-empty rectangular list of lists containing integers. Return a list containing each value exactly once in clockwise spiral order. The matrix may have different numbers of rows and columns.
After traversing one outer layer, continue inward until all remaining cells have been visited. Do not modify the input matrix.
def spiral_order(matrix):