Amazon interview question

Algorithm question: To print n by m dimensional matrix in spiral way.